I have a wordpress site with Matomo (Tag manager) On-premises version.
I need to activate statistics tracking via Cookies and I am using the wordpress ComplianZ plugin (which supports Matomo) to manager cookie consent.
I’m using ComplianZ to manage the Matomo Tag Manger “container”.
I should get this behavior:
User enters the site, Matomo Tag Manager start in “cookieless” mode tracking (therefore the cookie is not loaded),
If the user “Accepts” cookie tracking on the ComplianZ Plugin Banner, then the Matomo cookie is loaded.
If the user changes his/her preferences (by activating or deactivating cookies via the Complianz banner), the Matomo cookie is also updated accordingly.
I followed the various guides on both Matomo and ComplianZ sites, but without success.
This what curretly happens:
Matomo cookie is always loaded in any condition (even if user deny consent).
Add this extended code in ComplianZ > Integration > Script Center > Add Third Part Script:
(this replace the previous post code at point 3)
// Function to remember the consent given to the use of cookies when you click "I accept"
window._paq=window._paq||[];window._paq.push(['rememberCookieConsentGiven']);
// Function to withdraw consent. Read below to replace the XXXXs with the Matomo website ID
function withdrawConsent() {
window._paq.push(['forgetCookieConsentGiven']);
document.cookie = '_pk_id.XXXXXX=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; // Replace XXXXX with your ID
document.cookie = '_pk_ses.XXXXXX=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; // Replace XXXXX with your ID
}
// Add a listener for clicking the "Deny" button (check fo r correct button css class
document.addEventListener('DOMContentLoaded', function() {
var denyButton = document.querySelector('.cmplz-deny'); // Replace with the correct "Deny" button selector
if (denyButton) {
denyButton.addEventListener('click', function() {
withdrawConsent();
});
}
});