Respecting Do Not Track and Global Privacy Control
What you'll learn: How to detect and honor browser privacy signals so users can opt out of tracking without clicking through consent banners.
What Are DNT and GPC?
Two HTTP headers communicate user privacy preferences automatically:
- Do Not Track (DNT): An older header (
DNT: 1) indicating the user doesn't want to be tracked. Browser support varies, and it's not legally binding in most jurisdictions. - Global Privacy Control (GPC): A newer signal (
Sec-GPC: 1) that carries legal weight under CCPA and GDPR. It tells sites "this user opts out of data sharing/sale."
Think of these like a "Do Not Disturb" sign on a hotel room door—the guest has already made their preference clear before you knock.
Reading Privacy Signals in JavaScript
You can check these signals to disable analytics, personalization, or third-party scripts:
// Check Do Not Track
const dntEnabled = navigator.doNotTrack === '1'
|| window.doNotTrack === '1';
// Check Global Privacy Control
const gpcEnabled = navigator.globalPrivacyControl === true;
if (dntEnabled || gpcEnabled) {
console.log('User opted out of tracking');
// Don't load analytics scripts
// Don't send behavioral data
// Don't share data with third parties
} else {
// Proceed with tracking (if consent obtained)
}
Respecting the Signals
When either signal is detected:
- Don't load non-essential tracking scripts (Google Analytics, Facebook Pixel)
- Don't share user data with third-party advertisers
- Don't build behavioral profiles for personalization
- Do allow essential functionality like authentication and security
This respects user autonomy and can help with CCPA/GDPR compliance, especially for "Do Not Sell" obligations.
Key Takeaway: Check navigator.doNotTrack and navigator.globalPrivacyControl to honor users' expressed privacy preferences before loading tracking technologies—it's both ethical and increasingly legally required.