Respecting Do Not Track with Google Analytics

I'll disable google analytics

It's hard for me to talk about user privacy on this blog when I have Google Analytics measuring everything you do on the website. I've tried to move away from it in the past and use the self-hosted open-source alternative but it quickly failed. When I received a burst of traffic, the server on which it was hosted crashed. I'm still looking for a self-hosted solution but in the meanwhile, I will do what I can to limit tracking by respecting users that specifically ask not to be tracked.

Every browser gives you the option not to be tracked. When you activate this option (see below), the browser sets a global variable in JavaScript navigator.doNotTrack and it is accessible to all scripts that have the intention of tracking you. At that point, it is up to those scripts to decide to respect it or not. After doing some research, I found that Google Analytics does not respect this directive. On my websites it is up to me to respect it.

So as of September 26 2018 I have added a snippet of code that will respect the Do Not Track directive.

Below is the shim that tests it:

var _doNotTrack = navigator.doNotTrack ?
        navigator.doNotTrack === "1" || navigator.doNotTrack === "yes": 
        (window.doNotTrack? window.doNotTrack === "1": false);
if (_doNotTrack){
    // do not load GA
}

For now this script will determine if you have opted out of being tracked and will prevent Google Analytics from loading.

How to set Do Not Track on you browser

Google Chrome (Version 69):

Firefox:

Microsoft Edge:

Safari:

As far as I am concerned, if users have chosen not to be tracked, they will not be tracked with Google Analytics on this website. I hope other developers will join me on making sure we respect this rule.


Comments

There are no comments added yet.

Let's hear your thoughts

For my eyes only