Opt-out using the Matomo JavaScript Tracker code is triggert by page reload

After update matomo to 4.12.0 and replaced the legacy iframe opt-out with the new opt-out using the matomo javascript tracker code, the opt-out status is not saved or is exactly the opposite of the selected status after a page reload.

This matomo tracker js code is placed before </body>, but eaven in the <head>, the opt-out status is not saved correctly:

<script>
    var _paq = window._paq = window._paq || [];
    _paq.push(["disableCookies"]);
    _paq.push(['disableBrowserFeatureDetection']);
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="https://stats.REMOVED.de/";
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', '1']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
    })();
</script>

opt-out code in the page content (TYPO3 CMS):

<div id="matomo-opt-out"></div>
<script src="https://stats.REMOVED.de/index.php?module=CoreAdminHome&action=optOutJS&divId=matomo-opt-out&language=auto&showIntro=1"></script>

Strangely enough, the cookie “mtm_consent_removed” is sometimes set when the page is opened, even though the opt-out form checkbox is checked. After a page reload, the opt-out form checkbox is not active and the cookie is gone. Shouldn’t it be the other way around? After another reload of the page, the opt-out form checkbox is set again and the cookie “mtm_consent_removed” is also there again. If the checkbox is deactivated by clicking on it, the cookie is set correctly. But if i reload the page, the cookie is gone. I suspect there are errors in the script that controls the new opt-out form.

Browser security/privacy settings default.

Matomo-Version: 4.12.0
MySQL-Version: 10.5.17-MariaDB-1:10.5.17+maria~deb10
PHP-Version: 8.1.11

Update: Without the matomo tracking code on the page, it works like expected. I now use the standalone/self-contained opt-out code and everything works.

There has been changes on the opt-out:

Is it linked to this change?

Probably, i am not sure. Before this change or before matomo 4.12.0 i used the legacy iframe opt-out with the “custom opt-out” plugin.

Another issue with new opt-out js code is, if you use no consent tool (because of disabled tracking cookies) and use the default standalone js code from the admin opt-out ui, the checkbox of the opt-out form is always uncheckt by default, because no consent cookie is found. This is wrong in my eyes/usecase, because matomo tracking does not need consent by default. I have added an if statement to the function hasConsent to check if both cookies are missing and then return true.

I see that as a bug too. I created an issue. New Opt-out solution: checkbox is OFF per default even though I’m being tracked · Issue #19888 · matomo-org/matomo (github.com)

1 Like