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
- HTTP headers | Access-Control-Expose-Headers
- HTTP headers | Access-Control-Allow-Headers.
- HTTP headers | Access-Control-Request-Headers
- HTTP headers | Location
- HTTP headers | User-Agent
- HTTP headers | Link
- HTTP headers | Save-Data
- HTTP headers | Content-Type
- HTTP headers | X-XSS-Protection
- HTTP headers | X-Frame-Options
- HTTP headers | Last-Modified
- HTTP headers | Date
- HTTP headers | Cookie
- HTTP headers | Strict-Transport-Security
- HTTP headers | Expect
- HTTP headers | Accept-Encoding
- HTTP headers | Proxy-Authenticate
- HTTP headers | Content-Range
- HTTP headers | Content-Encoding
- HTTP headers | Content-Language
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.