DNT (Do Not Track)
Description
The Do Not Track (DNT) request header is an HTTP header field that allows users to indicate their preference regarding online tracking by websites and third-party services. When enabled, the DNT header signals that the user does not wish to be tracked across the internet by advertisers, analytics services, or other entities that collect browsing data.
DNT was introduced as part of a broader effort to enhance user privacy online. However, compliance with the DNT request is entirely voluntary, as there are no legal obligations for websites or advertisers to respect the signal. While some websites honor DNT preferences, many do not, making its effectiveness somewhat limited.
The DNT header has two main values:
1
: The user opts out of tracking.0
: The user allows tracking (rarely sent, as the default is typically no DNT header).
It is important to note that the DNT header is deprecated in modern browsers due to a lack of widespread adoption and adherence by websites. However, some privacy-focused tools and services still use it.
Syntax
The DNT header is included in HTTP requests and follows this syntax:
DNT: 1 // Indicates that the user does not wish to be tracked
DNT: 0 // Indicates that the user allows tracking
Examples
Basic Usage in HTTP Requests
When a user enables DNT in their browser settings, the HTTP request sent to a web server includes the following header:
This informs the server that the user does not wish to be tracked.
Checking DNT in Client-Side JavaScript
Although client-side scripts cannot change the DNT header, they can read its
value using the navigator.doNotTrack
property:
if (navigator.doNotTrack === "1") {
console.log("User has enabled Do Not Track");
// Adjust tracking behavior accordingly
} else {
console.log("User allows tracking or DNT is not set");
}
Summary
The DNT header was introduced as a privacy-enhancing feature but has seen limited adoption due to the lack of enforcement. While it provides users with a way to express their tracking preferences, most advertisers and analytics services do not honor it. As a result, many modern browsers have deprecated its support in favor of stronger privacy-focused features such as tracking prevention and stricter cookie policies.