Ok, let’s forget Borlabs (which is one of the best Wordpress consent tools) for now.
I just have to fields to fire code, one for opt-in and one for opt-out.When the user is opting in, this code I copied to the opt-in field:
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.esser.me/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
Great, everything is working now. Now the user is opting out and I have to tell the tool which code to fire to do so. I decided for:
<script type="text/javascript">
_paq.push(['optUserOut']);
</script>
This is working, too. The pk cookies are going awy and the mtm_conent_removed will be placed
Now the user re-opt-in and the first code will be loaded again:
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.esser.me/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
Great, it is working… the pk cookies will be set again. But the mt_consent_removed cookie will not be deleted. That’s why I added to the optin code the following way:
<!-- Matomo -->
<script>
_paq.push(['forgetUserOptOut']);
</script>
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.esser.me/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
Thought to make sure the opt-out is forgotten I fire the _paq.push([‘forgetUserOptOut’]); before firering the default matomo code… but this doesn’t change anything, the mtm_consent_removed cookie is still there.
This is what borlabs is writing regarding Matomo opt-out:
It is not necessary to include the opt-out iframe of Matomo. If Matomo is included via Borlabs Cookie, the code of Matomo will not be loaded in case of an opt-out. Therefore the opt-out function of Matomo is unnecessary and should not be included.
…but with the mtm_consent_removed plugin it looks like the opt-out function of Matomo is in place. Right??? How can I stop this?