Matomo (Piwik) Opt-Out
Home
Info

Matomo (Piwik) Opt-Out Cookie Javascript

For separate opt-out you can use this simple javascript with a function and set a opt-out cookie for each domain/website as well as each subdomains and subfolders. As an additional feature you find a Do Not Track detection JavaScript at the bottom of this webpage.

This Matomo (Piwik) Opt-Out cookie javascript is independently from your Matomo (Piwik) installation.

This Matomo (Piwik) Opt-Out cookie javascript works with older and newer Matomo (Piwik) script code snippets.

This Matomo (Piwik) Opt-Out cookie prevented the loading of the piwik.js javascript file wich are loaded by the Matomo (Piwik) script code snippet and also the saving of the Matomo (Piwik) cookies. Already saved cookies will not be deleted at the store of the Matomo (Piwik) Opt-Out cookie. But they are ineffective because the tracking script was not loaded.

This Matomo (Piwik) Opt-Out cookie javascript does not prevent <noscript> image tracking.

This Matomo (Piwik) Opt-Out cookie javascript differentiates between www and non-www Internet Domain Name URLs and differentiates Subdomains.

Live Example:

Javascript and the storage of cookies must be allowed in your browser.
Please activate JavaScript.
To check the Matomo/Piwik opt-out cookie, please reload these webpage.
The Matomo/Piwik Opt-Out Cookie is only valid for this domain and this browser.

You can control and test it with these three buttons.
    Reload Webpage
Please note: In addition, Matomo (Piwik) Tracking Tool is active on this webpage (cookies with "_pk"). Already saved Matomo (Piwik) cookies will not be deleted. With opt-out cookie these cookies have no function.

You must insert the marked javascript code into your Matomo (Piwik) javascript code snippet.
<!-- Matomo -->
<script type="text/javascript">
var matomodomainname = window.location.hostname;
var matomocookiename = "matomooptout" + matomodomainname.replace(/\./g, "");
if (document.cookie.indexOf(matomocookiename) < 0) {

var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//www.example.com/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '0']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();

</script>
<!-- End Matomo Code -->
Do not forget the closing curly bracket at the bottom of the javascript code.

And that is the HTML code snippet with javascript to save the opt-out cookie with click a button for your privacy policy. Use it instead of the Matomo (Piwik) Opt-Out iframe. There is an opt-out cookie check built-in.
Javascript and the storage of cookies must be allowed in your browser.
<div id="matomooptoutdivid" class="matomooptoutdivclass"><b>Please activate JavaScript.</b></div>
<script>
var matomodomainname = window.location.hostname;
var matomocookiename = "matomooptout" + matomodomainname.replace(/\./g, "");
if (document.cookie.indexOf(matomocookiename) < 0) {
var creatematomooptoutbutton = document.createElement("BUTTON");
var creatematomooptoutbuttontext = document.createTextNode("Save Matomo/Piwik Opt-Out Cookie");
creatematomooptoutbutton.appendChild(creatematomooptoutbuttontext);
creatematomooptoutbutton.setAttribute("id", "matomooptoutbuttonid");
creatematomooptoutbutton.setAttribute("class", "matomooptoutbuttonclass");
document.getElementById("ganalyticsoptoutdivid").innerHTML = "";
document.getElementById("matomooptoutdivid").appendChild(creatematomooptoutbutton);
creatematomooptoutbutton.onclick = function matomooptout() {
var matomocookienamevalue = matomocookiename + "=" + "optedout;expires=Wed, 1 Jan 2100 00:00:00 UTC;path=/";
document.cookie = matomocookienamevalue;
}
} else {
document.getElementById("matomooptoutdivid").innerHTML = "<b>INFO:</b> A Matomo/Piwik opt-out cookie for this domain and this browser is already exists.";
}
</script>
To check the Matomo/Piwik opt-out cookie, please reload these webpage.
<br>
The Matomo/Piwik Opt-Out Cookie is only valid for this domain and this browser.
If you want the opt-out cookie to work separately for individual subfolders, you must change the specification of "path = /".

The opt-out cookie button HTML code snippet with javascript is PHP valid. You can put it in a variable like $matomooptoutbuttoncode = '...';

You can style the HTML code via CSS. There is a div box and a button with id and class inside.
div id: #matomooptoutdivid
div class: .matomooptoutdivclass
button id: #matomooptoutbuttonid
button class: .matomooptoutbuttonclass



DO-NOT-TRACK DETECTION

Do Not Track detection PHP and/or JavaScript for your privacy policy.


1.) DoNotTrack detection - JavaScript only

Live Example:

DoNotTrack detection
Your Browser Do Not Track Status: - (JavaScript must be activated)

<div id="donottrackdivid" class="donottrackdivclass">DoNotTrack detection<br><div id="donottrackdivdivid" class="donottrackdivdivclass">Your Browser <b>Do Not Track</b> Status: - (JavaScript must be activated)</div></div>
<script>
if (navigator.doNotTrack == 1 || navigator.doNotTrack == "yes" || window.doNotTrack == 1 || navigator.msDoNotTrack == 1) {
donottrackstatustxt = "Your Browser <b>Do Not Track</b> Status: <b>On</b> (assumed)";
} else {
donottrackstatustxt = "Your Browser <b>Do Not Track</b> Status: <b>Off</b> (or unknown)";
}
document.getElementById("donottrackdivdivid").innerHTML = donottrackstatustxt;
</script>



2.) DoNotTrack detection - PHP only (used by Matomo)

Live Example:

DoNotTrack detection
Your Browser Do Not Track Status: Off (or unknown)

<div id="donottrackdivid" class="donottrackdivclass">DoNotTrack detection<br><div id="donottrackdivdivid" class="donottrackdivdivclass">Your Browser <b>Do Not Track</b> Status:
<?php
if ((isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1') || (isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1')) {
echo '<b>On</b> (assumed)';
} else {
echo '<b>Off</b> (or unknown)';
} ?>
</div>
</div>



3.) DoNotTrack detection - PHP and JavaScript Fallback

Live Example:

DoNotTrack detection
Your Browser Do Not Track Status: Off (or unknown, Please activate JavaScript)

<?php
if ((isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1') || (isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1')) {
$serverhttpdonottracktxtphp = "<b>On</b> (assumed)";
} else {
$serverhttpdonottracktxtphp = "<b>Off</b> (or unknown, Please activate JavaScript)";
} ?>
<div id="donottrackdivid" class="donottrackdivclass">DoNotTrack detection<br><div id="donottrackdivdivid" class="donottrackdivdivclass">Your Browser <b>Do Not Track</b> Status: <?php echo $serverhttpdonottracktxtphp; ?></div></div>
<script>
var serverhttpdonottrackphpjs = "<?php if (isset($_SERVER['HTTP_DNT'])) { echo $_SERVER['HTTP_DNT']; } ?>";
if (serverhttpdonottrackphpjs != 1) {
if (navigator.doNotTrack == 1 || navigator.doNotTrack == "yes" || window.doNotTrack == 1 || navigator.msDoNotTrack == 1) {
donottrackstatustxtjs = "Your Browser <b>Do Not Track</b> Status: <b>On</b> (assumed)";
} else {
donottrackstatustxtjs = "Your Browser <b>Do Not Track</b> Status: <b>Off</b> (or unknown)";
}
document.getElementById("donottrackdivdivid").innerHTML = donottrackstatustxtjs;
}
</script>


The Do Not Track detection PHP and/or JavaScript will be work on mostly desktop browser.
Firefox 9.0 and upwards, Chrome/Chromium 23 and upwards, Opera 12 and upwards, Safari 5.1 and upwards, Internet Explorer 9 and upwards.

You can style the HTML code via CSS. There is a div box and a div box in the div box with separate id and class inside.
div id: #donottrackdivid
div class: .donottrackdivclass
div div id: #donottrackdivdivid
div div class: .donottrackdivdivclass

Support Penultima.de
PayPal Gefällt Mir Button
© Penultima.de - All rights reserved. Data protection statement & Imprint & Contact
Cookies in use.
More Infos