JavaScript Navigator doNotTrack Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

navigator.doNotTrack returns the user’s legacy Do Not Track preference (MDN). Values match the DNT HTTP header: "1", "0", or null.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use navigator.doNotTrack. Start with this line.

JavaScript
navigator.doNotTrack
CallWhat it does
navigator.doNotTrackPrimary signature.

Built into the browser. Read navigator.doNotTrack on Navigator — no import required.

Library declarations
JavaScript
navigator.doNotTrack

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*"1" | "0" | null

JavaScript Examples

Example 1 — Read doNotTrack

MDN-style log of the current preference.

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

How It Works

  1. Read the property. No arguments — just navigator.doNotTrack.
  2. Expect a string or null. MDN documents "1", "0", or null.
  3. Log it. Useful for demos and debugging legacy code.
  4. Do not trust it alone. Sites historically ignored the preference.

Example 2 — Interpret the Value

Map the three possible results to plain-language labels.

JavaScript
function describeDnt(value) {
  if (value === "1") return "prefer not to be tracked";
  if (value === "0") return "tracking opted in";
  return "no preference";
}

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

How It Works

  1. Pass the raw value. Use strict equality on the strings.
  2. Handle "1". User asked not to be tracked.
  3. Handle "0". User opted in to tracking.
  4. Default for null. No preference expressed (or UI removed).

Example 3 — Prefer Global Privacy Control

For new code, check GPC when available instead of relying on DNT.

JavaScript
function privacyHint() {
  if ("globalPrivacyControl" in navigator) {
    return navigator.globalPrivacyControl
      ? "GPC: do not sell/share"
      : "GPC: false / unset";
  }
  // Legacy only — do not depend on this for enforcement
  return "DNT legacy: " + String(navigator.doNotTrack);
}

console.log(privacyHint());
Try It Yourself

How It Works

  1. Detect GPC first. Modern replacement path when the property exists.
  2. Read the boolean. true means do not sell/share (MDN).
  3. Fall back carefully. Only mention DNT for legacy awareness.
  4. Teach the migration. Students learn what to use next.

Browser Support

Navigator.doNotTrack is Non-standard on MDN. The DNT specification is discontinued and the HTTP DNT header is Deprecated. Some browsers still expose the property for compatibility; others return null or remove DNT UI.

✓ Non-standard · Discontinued

Navigator.doNotTrack

Legacy compatibility only. Prefer navigator.globalPrivacyControl / Sec-GPC for modern privacy preference signals.

Legacy Do not use for new work
Google Chrome May expose legacy DNT; do not rely on it
Legacy
Microsoft Edge Legacy compatibility varies
Legacy
Mozilla Firefox DNT setting removed (GPC preferred)
Legacy
Apple Safari Legacy / often unset
Legacy
Opera Chromium-based legacy exposure
Legacy
navigator.doNotTrack Legacy

Bottom line: Learn the values for interviews and old codebases, then migrate privacy logic to Global Privacy Control and enforceable protections.

Frequently Asked Questions

It returns the user’s Do Not Track preference as "1" (prefer not to be tracked), "0" (user opted in to tracking), or null (no preference). It mirrors the DNT HTTP header (MDN).
No. MDN marks it Non-standard; the DNT specification is discontinued and the DNT HTTP header is Deprecated. Prefer stronger privacy tools such as Global Privacy Control.
Browsers are moving toward features like Global Privacy Control (navigator.globalPrivacyControl / Sec-GPC), third-party cookie restrictions, and other enforceable protections — not cooperative DNT headers.
MDN: many sites ignored the preference, so it was ineffective. The signal can also add fingerprint entropy that helps trackers identify users.
No. It is a read-only Navigator property reflecting a browser preference (where the UI still exists).
Per MDN: "1" if DNT is enabled, "0" if the user opted in for tracking, otherwise null.

Prefer: globalPrivacyControl

Learn the modern Global Privacy Control preference signal next.

globalPrivacyControl →

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.

11 people found this page helpful