Open In App

HTTP headers | DNT

Last Updated : 11 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Syntax:

DNT:0
DNT:1

Directives :

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.

Examples:

  • 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
    
  • The value of DNT header field can be checked using JavaScript’s navigator.doNotTrack property.
    console.log(navigator.doNotTrack); 
    // prints "1" if DNT is enabled; "0" 
    // if the user opted-in for tracking;
    // prints "null" if unspecified
    
    1. Safari 7.1.3+ , Edge , IE11 and subsequent versions use window.doNotTrack rather than navigator.doNotTrack
    2. 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
  • Firefox
  • Opera

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads