Merge pull request #278 from OwnWeb/fix/matomo-first-party-cookies

Fix Matomo/Piwik cookies detection 🐛
This commit is contained in:
Amauri CHAMPEAUX 2019-03-08 18:02:11 +01:00 committed by GitHub
commit d514890675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
}
};