🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

DNT

HTTP Header

The HTTP <code>DNT</code> (Do Not Track) request header indicates the user’s tracking preferences.
It allows users to specify whether they prefer privacy over receiving personalized content.

The DNT feature is deprecated in favor of Global Privacy Control, which is communicated to servers using the <code>Sec-GPC</code> header, and can be accessed from clients through <code>navigator.globalPrivacyControl</code>.

Syntax

Here are some examples of how to set the Do Not Track (DNT) header in HTTP requests:

DNT: 0
DNT: 1
DNT: null

Directives

The user may choose to allow or deny tracking on a website, or may not specify a preference at all. The options are as follows:

0: The user prefers to allow tracking on the target site.

1: The user prefers not to be tracked on the target site.

null: The user has not specified a preference about tracking.

Example

The user’s Do Not Track (DNT) preference can be accessed via JavaScript using the Navigator.doNotTrack property:

js
navigator.doNotTrack; // "0", "1" or null

The Navigator.doNotTrack property indicates the user’s preference regarding tracking. A value of “1” means the user does not want to be tracked, “0” indicates the user allows tracking, and null signifies that the preference is unspecified.

It is part of the earlier, now discontinued, Tracking Preference Expression (DNT) specification.

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the DNT header. This can be very helpful to see how websites react when you change your “Do Not Track” preference, which is important for privacy settings. Steps to Modify the DNT Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter DNT.
    • In the “Header Value” field, enter 1 to enable Do Not Track or 0 to disable it.
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://example.com/*).
  5. Save the rule.

After setting this up, Requestly will add the DNT header with your chosen value to all matching requests, letting you test how different sites respond to Do Not Track signals.