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