The HTTP DNT Header is a request header that allows users to choose if their activity could be tracked by each server and web application that they communicate with via HTTP. The generated header field is a mechanism that allows the user to opt-in or out of the tracking. Tracking allows user to experience personalized content on web. The option to opt-out of tracking was created with growing privacy demands among users.
The tracking preference can only be set if a user has enabled it. A user agent is not allowed to display a tracking preference expression if not enabled tracking preference is set by the user.
The following field value is generated for HTTP DNT header field if the tracking preference is set as enabled
- 1: This directive indicates that user prohibits tracking at the target site.
- 0: This directive indicates that user allows tracking on or the user has granted an exception at the given target site.
Note : A DNT Header Field can have zero or more extensions. The extensions are determined by the user agent. A DNT header field can be inserted without a field value if the extension is defined but the tracking preference is not set.
- This is a example from W3C(World Wide Web Consortium) of a DNT header set to field value – 1:
GET /something/here HTTP/1.1 Host: example.com DNT: 1
console.log(navigator.doNotTrack); // prints "1" if DNT is enabled; "0" // if the user opted-in for tracking; // prints "null" if unspecified
- Safari 7.1.3+ , Edge , IE11 and subsequent versions use window.doNotTrack rather than navigator.doNotTrack
- Prior to Firefox 32, navigator.doNotTrack would report values of yes and no rather than 1 and 0.
Supported Browsers: The browsers supported by HTTP DNT Header are listed below
- Google Chrome
- Internet Explorer
- Microsoft Edge