diff --git a/README.md b/README.md index bbe4d5cd3c..b55f7670a5 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,8 @@ Nuxt DevTools collects anonymous telemetry data about general usage. This helps Nuxt DevTools' telemetry data is piped through [Nuxt Telemetry](https://github.com/nuxt/telemetry), meaning that Nuxt DevTools will respect your local and global Nuxt Telemetry settings. You can also opt-out Nuxt DevTools' telemetry in the Nuxt DevTools settings. +Nuxt DevTools also respects the [`DO_NOT_TRACK`](https://donottrack.sh/) environment variable convention — set `DO_NOT_TRACK=1` in your environment to disable Nuxt DevTools telemetry regardless of any other setting. + The data we collect is completely anonymous, not traceable to the source (using hash+seed), and only meaningful in aggregate form. No data we collect is personally identifiable or trackable. ### Events diff --git a/packages/devtools/src/server-rpc/telemetry.ts b/packages/devtools/src/server-rpc/telemetry.ts index ab0187b62a..5a7f0bc178 100644 --- a/packages/devtools/src/server-rpc/telemetry.ts +++ b/packages/devtools/src/server-rpc/telemetry.ts @@ -8,6 +8,17 @@ const SEND_DELAY = 5_000 type ArgumentsType = T extends (...args: infer A) => any ? A : never +/** + * Whether the user has opted out of tracking via the `DO_NOT_TRACK` + * environment variable convention. + * + * @see https://donottrack.sh/ + */ +function isDoNotTrackEnabled() { + const value = process.env.DO_NOT_TRACK + return value === '1' || value?.toLowerCase() === 'true' +} + function throttle any>(fn: T, delay: number) { let timer: ReturnType | undefined @@ -28,7 +39,7 @@ const throttledSend = throttle(() => { }, SEND_DELAY) export function setupTelemetryRPC({ nuxt, options }: NuxtDevtoolsServerContext) { - if (options.telemetry !== false) { + if (options.telemetry !== false && !isDoNotTrackEnabled()) { // Only when global telemetry is enabled, the hook will be called nuxt.hook('telemetry:setup', (t) => { telemetry = t @@ -58,6 +69,9 @@ export function telemetryEvent(payload: object, immediate = false) { if (getOptions()?.behavior.telemetry === false) return + if (isDoNotTrackEnabled()) + return + telemetry.createEvent('devtools', payload) if (immediate)