Visitors that do not want to be tracked - How to set up an opt out button on your website

Modified on: Thu, 16 Sep, 2021 at 9:19 AM

To accommodate the wishes of visitors that do not want their visitor information tracked, Siteimprove has created a cookie for our customers to implement on their website(s).

See also the related article - IP Anonymization in Siteimprove Analytics
Please contact your development team or agency to set up the solution. You can either set up a link/button that lets your visitors opt-out of being tracked or alternatively you can create an opt-out/opt-in toggle switch. 

Setting up an Opt-Out Button or Link

Opt-Out from Siteimprove Analytics Tracking can be controlled via JavaScript by calling:

_sz.push(['notrack']);

After this command has been executed, the Analytics script will stop tracking the visitor.

The code can be placed within a link:

<a href="#" onclick="_sz.push(['notrack']); return false;">Opt-out of Siteimprove Analytics</a> 

The following code can be used for creating an undo opt-out link (you might want to call it opt-in link):

<a href="#" onclick="_sz.push(['notrack', false]); 
return false;">Opt-In to Siteimprove Analytics again</a>

The current state of tracking (Opt-In/Opt-Out) is read with:

_sz.tracking();

This could be useful in a dialog with the end-user, as for example like this:

_sz.push(['notrack', confirm('Are you being tracked: ' + (_sz.tracking() ? 'Yes' : 'No') + '. 
Pres OK if you want to opt out, CANCEL otherwise')]);

The tracking state is kept in a cookie in the end user's browser.

Implement an opt-in/opt-out switch (toggle):
Use the following button definition:

<button id="szOptOutIn">Opt out</button>

instead of:

<button onclick="_sz.push(['notrack', confirm('Are you being tracked:
' + (_sz.tracking() ? 'Yes' : 'No') + '. Press OK if you want to opt out, CANCEL otherwise')]);">
Opt Out or Opt In</button>

as seen above in the end-user dialog example.
Add this code on your page where you want to have your Opt-out/Opt-in button:

<button id="szOptOutIn">Opt out</button>
<script type="text/javascript">
function changeOptSetting(obj, txtOptIn, txtOptOut) { if(_sz){ obj.innerHTML=_sz.tracking()?txtOptOut:txtOptIn; obj.onclick = function() { _sz.push(['notrack', _sz.tracking()]); obj.innerHTML=_sz.tracking()?txtOptOut:txtOptIn; }; } } changeOptSetting(document.getElementById("szOptOutIn"), "Opt In", "Opt Out");
</script>

 

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.