[SOLVED] Matomo Tag manager on Premises + ComplianZ Cookie Plugin on Wordpress problem

Hello everyone,

I’m trying to solve this problem:

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:

  1. User enters the site, Matomo Tag Manager start in “cookieless” mode tracking (therefore the cookie is not loaded),

  2. If the user “Accepts” cookie tracking on the ComplianZ Plugin Banner, then the Matomo cookie is loaded.

  3. 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).

How can I solve it?

Thanks in advance!

I momentary found a partial solution:

  1. Under ComplianZ: I set ComplianZ plugin to manage the Matomo Tag Manager Container with standard procedure,
  2. Under Matomo Tag Manager: I set my general tracking variable with “Ask for cookie consent” option,
  3. Under ComplianZ: go to Integration > Script center > Add Third Part Script > insert here this code:
window._paq=window._paq||[];window._paq.push(['rememberCookieConsentGiven']);

Now the the situation is this:

  1. user enter the site and Matomo cookie is not loaded (but Matomo is still tracking statistic in cookieless mode),
  2. if user give the consent then Matomo cookie is correclty loaded,

BUT a problem still persist!

If a user decide later to “Deny” the consent previously given, the cookie is not deleted.

Any idea to solve this last piece of the puzzle??

Thanks!
Bye.

[SOLVED] in this way.

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();  
        });  
    }  
});