Analytics with Ottimo
Help your readers take control of their data with this script
content-stack-utilities/ga-optout.html at ec732ae072fc8fc52f040587f90721cf6a5bcdb8 · ercule/content-stack-utilities
Contribute to ercule/content-stack-utilities development by creating an account on GitHub.
Our intent with this code is to offer a useful utility – but it has some downsides that we list below, and will probably need a bit of customization for your use case.
But more importantly, we want to get marketers thinking: Do you really need Google Analytics to run an effective marketing department?
Quick overview of the opt-out code
The key line of this code is Google’s functionality to turn off tracking:
window['ga-disable-' + gaProperty] = true;
Every other line of the code provides the additional functionality described above. For example,
setCookie() are fairly standard cookie functions to save and read whether your users has disable GA tracking. The
checkCookie() function uses
readCookie() to see if an option for disabling tracking has been set;
checkCookie() also manages toggling the link text to switch between opted-in and opted-out states.
To use this, you can drop the code more or less unchanged into any page on your site; that’s what we’ve done with our blog post. The
<a> element will work anywhere you place it, and if you have access to a web developer, they can attach this behavior to a button or some other element, instead.
Caveats and warnings
- Ideally, you should have this code run before your Google Analytics code runs. If Google Analytics is implemented via Google Tag Manager on your site, the easiest way to do that is to take the code between the
<script>tags and add it to a new GTM tag that fires before Google Analytics.
- Another good reason to use Google Tag Manager: This code needs to run on every page of your site where Google Analytics runs.
- If you’re subject to the requirements of GDPR or any similar legislation – this code isn’t going to be enough to cover those requirements. We don’t offer legal advice, but there are plenty of Cookie Consent companies out there that offer a full solution to this problem.
- This code sets its own cookie. The irony isn’t lost on us! It’s just a few letters –
optedout– and we tend to think that simpler cookies, that you control directly, are better. But still.
- This only works for a single Google Analytics tracker, so if you’re using more than one, you’ll need to modify the code to account for that.
This short script makes it relatively straightforward to allow your users to disable Google Analytics. We’ll continue to develop this code, but mostly we hope this sparks a conversation for you about whether, and how, you want to continue using Google’s tool. Questions? Feel free to chat with us, or open an issue in the GitHub repo.
Everything we have to say on SEO, content performance, and content analytics – in convenient email form.
(Having doubts? Here's a recent issue.)