JavaScript Navigator doNotTrack Property

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Non-standard

What You’ll Learn

navigator.doNotTrack reflects the user’s old Do Not Track preference ("1", "0", or null). Learn why DNT failed, the values, safer alternatives, five examples, and try-it labs.

01

Kind

Read-only property

02

Returns

String or null

03

Status

Deprecated

04

Standard?

Non-standard

05

Values

"1" / "0" / null

06

Use today?

Avoid

Introduction

Do Not Track was meant to be a polite signal: the user asks sites not to track them, and sites voluntarily comply. In practice, many advertising systems ignored the signal.

navigator.doNotTrack exposes that preference in JavaScript (matching the DNT HTTP header). MDN now treats the whole approach as discontinued — ineffective for privacy and potentially harmful as fingerprinting noise.

💡
Learning vs shipping

This tutorial explains the property so you can recognize legacy code. Do not build new privacy logic on DNT alone.

Understanding the doNotTrack Property

Think of doNotTrack as a historical preference flag — not an enforceable lock against trackers.

  • "1" — user requests not to be tracked (DNT enabled).
  • "0" — user opted in to tracking (per MDN’s example notes).
  • null — no preference / unset in many browsers.
  • HTTP twin — same idea as the DNT request header.
  • Why it failed — cooperative only; ignored by many trackers; added fingerprint bits.

📝 Syntax

General form of the property:

JavaScript
navigator.doNotTrack

Value

  • A string ("1" or "0") or null.

Common patterns (legacy / learning only)

JavaScript
// MDN-style log (do not rely on this for privacy):
console.log(navigator.doNotTrack);
// "1" if DNT enabled; "0" if opted-in; otherwise null

// Prefer modern signals when available:
if (navigator.globalPrivacyControl === true) {
  // User has Global Privacy Control enabled (where supported)
}

⚡ Quick Reference

GoalCode / note
Read DNTnavigator.doNotTrack
Request no tracking"1"
Opted in"0"
Unsetnull
New projectsDo not use (deprecated)
Modern check (where available)navigator.globalPrivacyControl

🔍 At a Glance

Four facts to remember about navigator.doNotTrack.

Returns
"1" | "0" | null

Preference

Status
deprecated

Avoid shipping

Standard
non-standard

Discontinued DNT

Better path
GPC / cookies

Enforceable privacy

📋 DNT vs Modern Privacy Signals

navigator.doNotTrackModern approaches
ModelAsk sites politelyBrowser / law / GPC enforcement
StatusDeprecated + Non-standardActively evolving
ReliabilityOften ignoredStronger when browser-enforced
Side effectExtra fingerprint bitDesigned to reduce tracking
Use in new apps?NoYes — follow current guidance

Examples Gallery

Examples follow MDN navigator.doNotTrack patterns for learning. Prefer Try It Yourself to inspect your browser. Do not treat these checks as a complete privacy solution.

📚 Getting Started

Read the raw value and map it to plain language.

Example 1 — Read doNotTrack

MDN-style console log of the current preference.

JavaScript
console.log(navigator.doNotTrack);
// prints "1" if DNT is enabled; "0" if opted-in; otherwise null
Try It Yourself

How It Works

Many modern setups return null because DNT UI was removed or defaults to unset.

Example 2 — Human-Readable Label

Translate the value into a short status string (for demos only).

JavaScript
function dntLabel(value) {
  if (value === "1") return "DNT: request no tracking";
  if (value === "0") return "DNT: opted in to tracking";
  return "DNT: unset / null";
}

console.log(dntLabel(navigator.doNotTrack));
Try It Yourself

How It Works

Useful for teaching the three outcomes — not for enforcing privacy policy.

📈 Practical Patterns

Type checks, legacy branching, and a modern GPC-aware helper.

Example 3 — Value & Type

Show both the value and its JavaScript type.

JavaScript
const v = navigator.doNotTrack;
const lines = [
  "value: " + String(v),
  "typeof: " + typeof v
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

When the value is null, typeof is "object" — a classic JS quirk beginners should know.

Example 4 — Legacy Branch (Do Not Copy)

How old code sometimes branched — shown only so you can recognize it.

JavaScript
// Legacy pattern — NOT recommended for new apps
function legacyShouldReduceTracking() {
  return navigator.doNotTrack === "1";
}

console.log(
  "legacy reduce tracking?: " + legacyShouldReduceTracking()
);
Try It Yourself

How It Works

Even when true, this never guaranteed trackers would stop — which is why DNT was discontinued.

Example 5 — Prefer GPC When Present

Combine a deprecated DNT read with a modern Global Privacy Control check.

JavaScript
function privacySignals() {
  return {
    doNotTrack: navigator.doNotTrack, // deprecated — diagnostic only
    globalPrivacyControl:
      typeof navigator.globalPrivacyControl === "boolean"
        ? navigator.globalPrivacyControl
        : "unsupported",
    advice: "Do not rely on DNT for new privacy logic"
  };
}

console.log(JSON.stringify(privacySignals()));
Try It Yourself

How It Works

Use this mindset in refactors: keep DNT only if you must debug legacy systems; prefer GPC and legal consent flows for new work.

🚀 Common Use Cases

  • Learning / interviews — explain why cooperative DNT failed.
  • Legacy audits — find old doNotTrack === "1" branches to remove.
  • Support diagnostics — log the value only with other privacy signals.
  • Migration — replace DNT checks with GPC + consent tooling.
  • Not for new tracking gates — DNT alone is not a compliance strategy.

🧠 How navigator.doNotTrack Works

1

User sets a preference

Browser DNT setting (where the UI still exists).

Preference
2

Exposed as JS + header

navigator.doNotTrack and the DNT HTTP header.

Signal
3

Sites were asked to comply

Cooperative model — no hard enforcement.

Hope
4

Spec discontinued

MDN: unused by many trackers and harmful as fingerprinting noise.

📝 Notes

  • Deprecated and Non-standard on MDN — do not use in new production privacy logic.
  • Values are "1", "0", or null.
  • DNT was cooperative; many trackers ignored it.
  • MDN warns DNT can increase fingerprinting surface.
  • Related: globalPrivacyControl, geolocation, JavaScript hub.

Legacy / Declining Support

navigator.doNotTrack is Deprecated and Non-standard. Some browsers still expose it for compatibility; others return null or remove DNT UI. Do not depend on it for privacy.

Deprecated · Non-standard

Navigator.doNotTrack

Learn the values for legacy code. Prefer Global Privacy Control and enforceable browser protections for new work.

Legacy Avoid in new apps
Google Chrome Legacy DNT — often unset / limited UI; check current behavior
Legacy
Microsoft Edge Chromium-based — follow current DNT exposure
Legacy
Opera Legacy exposure may vary
Legacy
Mozilla Firefox Historically exposed DNT; treat as legacy
Legacy
Apple Safari Tracking prevention differs — do not rely on doNotTrack
Legacy
doNotTrack Legacy

Bottom line: Read doNotTrack only to understand or remove legacy branches — never as your sole privacy control.

Conclusion

navigator.doNotTrack is a deprecated, non-standard snapshot of the old DNT preference. Learn the "1" / "0" / null values so you can read legacy code — then migrate to stronger privacy mechanisms.

Continue with geolocation, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Treat DNT as historical knowledge
  • Remove or replace legacy doNotTrack gates
  • Prefer GPC / consent / browser protections
  • Document why you are not using DNT
  • Check MDN before keeping any DNT code

❌ Don’t

  • Ship new features that depend on DNT
  • Claim “we respect DNT” as full compliance
  • Use DNT as a unique user fingerprint
  • Ignore laws that require real consent tooling
  • Assume "1" stops all third-party trackers

Key Takeaways

Knowledge Unlocked

Five things to remember about doNotTrack

Deprecated DNT signal — learn it, don’t ship on it.

5
Core concepts
02

Status

Deprecated

Avoid
🚫 03

Standard

Non-standard

Legacy
🔍 04

Problem

Often ignored

Why failed
🔒 05

Better

GPC / protections

Modern

❓ Frequently Asked Questions

It returns the user’s Do Not Track preference as a string "1" (request not to be tracked), "0" (user opted in to tracking), or null (no preference / unset). It mirrors the DNT HTTP header.
No. MDN marks it Deprecated and Non-standard. The DNT specification was discontinued because it relied on voluntary cooperation and was widely ignored, while also adding fingerprinting surface.
Browsers are moving toward enforceable privacy features such as Global Privacy Control (for example navigator.globalPrivacyControl where available), third-party cookie restrictions, and stronger tracking protections — not cooperative DNT headers.
MDN notes the signal can add fingerprint entropy in headers/APIs. Trackers that ignored the preference could still use the presence of DNT as another identifying bit.
No. It is a read-only Navigator property reflecting the browser preference. Users change it in browser settings (where the UI still exists).
Per MDN’s example: "1" if DNT is enabled, "0" if the user opted in for tracking, otherwise null.
Did you know?

MDN’s blunt takeaway: DNT was not only ineffective — it could help trackers by adding another distinguishing bit to the user’s fingerprint while still being ignored.

Learn geolocation Next

Geolocation API for maps and local results (with permission).

geolocation →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful