From 3c95aa4c0935d06ca3da36001f3e99a68468a6b9 Mon Sep 17 00:00:00 2001 From: Hugo Heneault Date: Tue, 18 Dec 2018 17:17:18 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20Matomo/Piwik=20cookies=20detection=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #259 --- tarteaucitron.services.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tarteaucitron.services.js b/tarteaucitron.services.js index 9476850..72c7a54 100644 --- a/tarteaucitron.services.js +++ b/tarteaucitron.services.js @@ -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) } };