The solution looked great - until i tried to implement it 
@PraeSenZ: if you are using wordpress, the following works.
Be advised though, i don’t usually code javascript. Could anybody check my work in case i’ve missed something?
Now, step for step to a working implementation.
First: back up your Wordpress and matomo files and databases! You are going to fiddle with some inner works of matomo here. Make sure you can get back to a working version if something goes wrong.
Then take the example code from the linked page and remove all newlines:
<div id="optout-form"><p>You may choose not to have a unique web analytics cookie identification number assigned to your computer to avoid the aggregation and analysis of data collected on this website.</p><p>To make that choice, please click below to receive an opt-out cookie.</p><p><input type="checkbox" id="optout" /><label for="optout"><strong></strong></label></p></div><script>document.addEventListener("DOMContentLoaded", function(event) {function setOptOutText(element) {_paq.push([function() {element.checked = !this.isUserOptedOut();document.querySelector('label[for=optout] strong').innerText = this.isUserOptedOut()? 'You are currently opted out. Click here to opt in.': 'You are currently opted in. Click here to opt out.';}]);}var optOut = document.getElementById("optout");optOut.addEventListener("click", function() {if (this.checked) {_paq.push(['forgetUserOptOut']);} else {_paq.push(['optUserOut']);}setOptOutText(optOut);});setOptOutText(optOut);});</script>
Log in to wordpress and edit the site with the current iFrame. Change from visual to text editor, remove the iFrame and instead paste the code from above.
(If you’re wondering about the removed line breaks: even in text mode, wordpress inserts <p> ... </p>
tags around every line - this breaks the javascript if it contains more than one line).
Save, load the webpage (cookies still disabled in the matomo tracking code), click the checkbox-text and see… nothing. As it turns out, the request to not set cookies also affects the setting of the opt-out-cookie.
Now the fun starts, as we begin to change minimized javascript code. Go to your web space, get into the matomo installation dir and search for “piwik.js”. Make a copy (i.e. piwik.js.old), so you can get back without playing back the whole backup. Open “piwik.js” in an editor of your choice and search for “this.rememberConsentGiven=function(c5)”. For readability, here with newlines:
this.rememberConsentGiven=function(c5) {
if(bd){
ag("rememberConsentGiven is called but cookies are disabled, consent will not be remembered");
return
}
if(c5) {
c5=c5*60*60*1000
}
this.setConsentGiven();
var c4=new Date().getTime();
cZ(a6,c4,c5,bh,cL,bJ)
};
this.forgetConsentGiven=function() {
if(bd) {
ag("forgetConsentGiven is called but cookies are disabled, consent will not be forgotten");
return
}
bP(a6,bh,cL);
cZ(cB,new Date().getTime(),0,bh,cL,bJ);
this.requireConsent()
};
this.isUserOptedOut=function(){return !bt};
this.optUserOut=this.forgetConsentGiven;
this.forgetUserOptOut=this.rememberConsentGiven;
remove the if(bd){...}
-parts, so the function actually does anything:
this.rememberConsentGiven=function(c5){
if(c5){c5=c5*60*60*1000}this.setConsentGiven();var c4=new Date().getTime();cZ(a6,c4,c5,bh,cL,bJ)};this.forgetConsentGiven=function(){bP(a6,bh,cL);cZ(cB,new Date().getTime(),0,bh,cL,bJ);this.requireConsent()};this.isUserOptedOut=function(){return !bt};this.optUserOut=this.forgetConsentGiven;this.forgetUserOptOut=this.rememberConsentGiven;
That’s not enough, I’m afraid - you also need to disable the check for “not allowed cookies” in the function where the cookie is set (here cZ). You can’t outright remove the check, for this may also disable the no-cookie-parameter completely. So to be safe, use an optional override-parameter. Add , true
to cZ(...)
function calls:
this.rememberConsentGiven=function(c5){
if(c5){c5=c5*60*60*1000}this.setConsentGiven();var c4=new Date().getTime();cZ(a6,c4,c5,bh,cL,bJ,true)};this.forgetConsentGiven=function(){bP(a6,bh,cL);cZ(cB,new Date().getTime(),0,bh,cL,bJ,true);this.requireConsent()};this.isUserOptedOut=function(){return !bt};this.optUserOut=this.forgetConsentGiven;this.forgetUserOptOut=this.rememberConsentGiven;
Now search for “function cZ(”
function cZ(da,c8,c7,c9,c6,c5){if(bd){return}var c4;if(c7){c4=new Date();c4.setTime(c4.getTime()+c7)}G.cookie=da+"="+t(c8)+(c7?";expires="+c4.toGMTString():"")+";path="+(c9||"/")+(c6?";domain="+c6:"")+(c5?";secure":"")}
and add the override
function cZ(da,c8,c7,c9,c6,c5,overRide=false){if(!overRide&&bd){return}var c4;if(c7){c4=new Date();c4.setTime(c4.getTime()+c7)}G.cookie=da+"="+t(c8)+(c7?";expires="+c4.toGMTString():"")+";path="+(c9||"/")+(c6?";domain="+c6:"")+(c5?";secure":"")}
The function bP (removes cookie) needs a pass-through parameter as it calls cZ (Attention: add “,false,overRide” to the cZ function call - her it’s only called with 5 parameters instead of the expected 6)
function bP(c6,c5,c4,overRide=false){cZ(c6,"",-86400,c5,c4,false,overRide)}
Don’t forget to change the bP call in this.forgetConsentGiven
:
bP(a6,bh,cL, true);
Lastly, there’s also a call to setConsentGiven, which also calls bP. This time, add the override only in the function call:
this.setConsentGiven=function(){bt=true;bP(cB,bh,cL,true);var c5,c4;for(c5=0;c5<cz.length;c5++){c4=typeof cz[c5];if(c4==="string"){bw(cz[c5],bA)}else{if(c4==="object"){c0(cz[c5],bA)}}}cz=[]}
That’s it - Save the file, reload the webpage and test it. Be sure to reload after every click on the opt-out / opt-in - even if you just make the first change (remove if(bd){...}
), the text will toggle - but it won’t set the cookies.
This solution will not survive an update. If someone has a better idea to only set the opt-out cookie, i’m all ears.