npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

privacy-signals

v0.1.0

Published

Detect browser privacy opt-out signals: Do Not Track and Global Privacy Control

Readme

privacy-signals

Detect browser privacy opt-out signals: Do Not Track and Global Privacy Control.

Use it to gate analytics, error reporting, or any other tracking on the user's browser-level opt-out, without sprinkling non-standard navigator property checks through your code.

  • Checks every place browsers have exposed these signals: navigator.doNotTrack, window.doNotTrack, navigator.msDoNotTrack, and globalPrivacyControl on both navigator and window
  • Handles the legacy "yes" value some older browsers report alongside the modern "1"
  • Safe outside the browser: returns null instead of throwing when there is no browsing context to read
  • Zero dependencies, ESM, TypeScript types included

Install

pnpm add privacy-signals
# or: npm install privacy-signals

Usage

import { isTrackingOptedOut } from "privacy-signals";

if (isTrackingOptedOut() === false) {
  initAnalytics();
}

Compare against false rather than writing if (!isTrackingOptedOut()). The unknown case is null, which is falsy, so the negation form would start tracking during server-side rendering.

When you need to know which signal fired, read them separately:

import { getPrivacySignals } from "privacy-signals";

const signals = getPrivacySignals();
if (signals === null) {
  // Unknown: no browsing context to read, e.g. server-side rendering.
  // Do not treat this as "no opt-out"; re-check on the client, where
  // the signal actually lives.
} else if (signals.globalPrivacyControl) {
  // GPC carries legal weight under CCPA/CPRA; handle the opt-out request.
}

Avoid signals?.globalPrivacyControl as a bare condition: it collapses null into the no-opt-out path, the same trap as !isTrackingOptedOut() above.

API

isTrackingOptedOut(): boolean | null

| Result | Meaning | | ------- | ------------------------------------------------------------------------------------------------------ | | true | The user has opted out, via Do Not Track or Global Privacy Control. | | false | The browser was readable and reported no opt-out, including an explicit opt-in (doNotTrack === "0"). | | null | The signals could not be read at all: not a browsing context, or reading threw. |

null is not consent. Decide deliberately what your app does with it: defer the call to the client where the real answer lives, or treat unknown as opted out if you want the conservative default.

Server runtimes — Node 21+, Deno, Bun, edge — define a minimal global navigator, so checking that navigator exists is not enough on its own; doing that alone would report false on the server and assert an opt-out that was never read. Server-side rendering returns null.

getPrivacySignals(): PrivacySignals | null

Reads the two signals separately, each normalized to a boolean:

type PrivacySignals = {
  doNotTrack: boolean;
  globalPrivacyControl: boolean;
};

Use this when the distinction matters. Global Privacy Control is a legal opt-out request under CCPA/CPRA; Do Not Track never carried that weight. Returns null in exactly the cases isTrackingOptedOut() does: no browsing context, or reading threw. isTrackingOptedOut() is just the OR of the two fields.

Workers

Web workers and service workers are supported. The GPC spec exposes the signal on WorkerNavigator as well as Navigator, deliberately covering dedicated, shared, and service workers, so a worker gets a real answer rather than null.

Outside a window, the check is whether navigator actually carries one of these properties, not whether the global scope looks worker-shaped. Cloudflare Workers and similar edge runtimes present a ServiceWorkerGlobalScope while giving navigator only userAgent and sendBeacon, so testing for the property itself is what tells a browser worker apart from an edge server. Those runtimes still return null.

A note on Do Not Track

Do Not Track was deprecated in 2018 and browsers have been dropping it, so navigator.doNotTrack is absent or always null in a growing share of them. Global Privacy Control is its replacement and the one that carries legal weight under CCPA/CPRA. This package keeps reading both, because a browser that still reports DNT is still telling you something, but treat GPC as the signal that matters.

License

MIT