Global optout is not working: this.isUserOptedOut always return FALSE

Hello, thank you for developping Matomo!

I’m trying to have the global optout feature working as described here:

When i copy&paste the example and test this.isUserOptedOut(), the return value is always FALSE despite the fact that i check or uncheck the opt in/out box.
How could i debug this please?

Thank you.

Can you share the full custom opt-out JavaScript code?


document.addEventListener("DOMContentLoaded", function(event) {
  function setOptOutText(element) {
    _paq.push([function() {
      element.checked = !this.isUserOptedOut();
      document.querySelector('label[for=matomo-optout]').innerText = this.isUserOptedOut()
        ? "Vous refusez le suivi dans nos statistiques. Cocher cette case pour l'autoriser."
        : 'Vous autorisez le suivi dans nos statistiques. Décocher cette case pour le refuser.';

  var optOut = document.getElementById("matomo-optout");
  optOut.addEventListener("click", function() {
    if (this.checked) {
    } else {

Just to be sure (sometimes one can spent hours on a spelling error :wink: ): Are you sure you pass inside the if (this.checked) {clause (on check) and other in the else clause?

Yes, i removed the debug but the two cases of the if statement are triggered correctly.

I just saw that Matomo announced a new version of the feature and fixed an issue that might be related:

I’ll test if this fixes the above issue.

1 Like

Several tickets about user opt out have been closed: The one you mentioned, but also:

I tested the new optout process and the cookie was never set to remember the user choice :confused:
I gave up on having this working for now.

Hi, I don’t know if it’s the same problem of thread.
In my case, every time I refresh the page that contains the opt out script, it changes the status alternating between accepted flag and rejected flag.
In the meantime, analyzing the site, the mtm_consent_removed cookie is always injected in both modes and the tracking takes place in both modes.
If it helps in the investigation, I tried to implement Matomo on the site with the WP plugin, inserting the script in the header and having it configured by the plugin I use for the cookie banner (Complianz).
In all three cases the problem is the same.
Is it a software bug or is it my specific problem?
Thanks in advance to who can give me a suggestion.


Fixed in last version of Matomo: Matomo 4.13.0 Changelog