Skip to main content


Showing posts from May, 2018

How to correctly check for Do Not Track with JavaScript

Every modern browser has a Do Not Track setting, which tells sites whether the user wants to be tracked or not. Many sites don't respect this setting, but it's there regardless.

However, checking the value of this setting is far more complicated than it needs to be. Major browsers are split on whether it should be `navigator.doNotTrack` or `window.doNotTrack`, and the value can either be a string, a Boolean, or `undefined`. Here's how it boils down:

Chrome, Opera, and other Blink-based browsers use `navigator.doNotTrack`, with values of either `1` for true or `0` for false. Firefox also uses `navigator.doNotTrack` with the same values, but older versions use a different syntax. Prior to v32, Firefox would report `yes`, `no`, or `unspecified` (more info).Safari 7.1.3 and later use `window.doNotTrack`, while older versions use `navigator.doNotTrack`.Microsoft Edge and Internet Explorer 11 use `window.doNotTrack`, and reports `1` when enabled and 'unspecified' (Edge) …