Analytics opt-out button snippet
Copy a ready-made opt-out button for your privacy policy page that lets visitors stop being counted by Privatus Analytics in their browser, and how it works.
Visitors can opt out of being counted in their browser. Put this on your privacy policy page. It works wherever the tracker is installed.
html
<p id="privatus-optout-status">Checking…</p>
<button type="button" id="privatus-optout-button" hidden>Change</button>
<script>
(function () {
var status = document.getElementById('privatus-optout-status');
var button = document.getElementById('privatus-optout-button');
function render() {
if (!window.privatus || !privatus.isOptedOut) {
status.textContent = 'Analytics isn’t running in this browser, so your visits aren’t counted.';
return;
}
var out = privatus.isOptedOut();
status.textContent = out
? 'Your visits to this site are not counted.'
: 'Your visits are counted without cookies.';
button.textContent = out ? 'Count my visits again' : 'Don’t count my visits';
button.hidden = false;
}
button.addEventListener('click', function () {
privatus.isOptedOut() ? privatus.optIn() : privatus.optOut();
render();
});
window.addEventListener('load', render);
})();
</script>
- The choice is stored as
privatus_optout=1inlocalStorageon your domain, only after the visitor clicks. That's the only thing the Privatus Analytics tracker ever stores in a browser. - It applies to this browser and this domain. Subdomains (
shop.,blog.) have their own storage, so add the button there too, or on each domain you use. - Clearing site data removes the choice.
- While the choice is set, the tracker sends nothing from that browser.
- If the tracker is blocked (for example by an extension), the snippet says so and keeps the button hidden: nothing is counted in that browser anyway.
- The snippet assumes the default
privatusglobal. If you setdata-namespaceon the tracker, use that name instead.
With our WordPress plugin, use the [privatus_optout] shortcode instead. The tracker API
behind this is described in Opt-out.