Fix Matomo/Piwik cookies detection 🐛

Fix #259
This commit is contained in:
Hugo Heneault 2018-12-18 17:17:18 +01:00
parent e42eeaef9b
commit 3c95aa4c09
1 changed files with 22 additions and 0 deletions

View File

@ -2462,6 +2462,28 @@ tarteaucitron.services.matomo = {
}]);
tarteaucitron.addScript(tarteaucitron.user.matomoHost + 'piwik.js', '', '', true, 'defer', true);
// waiting for piwik to be ready to check first party cookies
var interval = setInterval(function() {
if (typeof Piwik === 'undefined') return
clearInterval(interval)
// make piwik/matomo cookie accessible by getting tracker
Piwik.getTracker();
// looping throught cookies
var theCookies = document.cookie.split(';');
for (var i = 1 ; i <= theCookies.length; i++) {
var cookie = theCookies[i-1].split('=');
var cookieName = cookie[0].trim();
// if cookie starts like a piwik one, register it
if (cookieName.indexOf('_pk_') === 0) {
tarteaucitron.services.matomo.cookies.push(cookieName);
}
}
}, 100)
}
};