Skip to content

Commit 190ff43

Browse files
authored
feat(devtools): respect DO_NOT_TRACK environment variable (#1064)
1 parent eeb29a9 commit 190ff43

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ Nuxt DevTools collects anonymous telemetry data about general usage. This helps
177177

178178
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.
179179

180+
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.
181+
180182
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.
181183

182184
### Events

‎packages/devtools/src/server-rpc/telemetry.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ const SEND_DELAY = 5_000
88

99
typeArgumentsType<T>=Textends(...args: infer A)=>any ? A : never
1010

11+
/**
12+
* Whether the user has opted out of tracking via the `DO_NOT_TRACK`
13+
* environment variable convention.
14+
*
15+
* @see https://donottrack.sh/
16+
*/
17+
functionisDoNotTrackEnabled(){
18+
constvalue=process.env.DO_NOT_TRACK
19+
returnvalue==='1'||value?.toLowerCase()==='true'
20+
}
21+
1122
functionthrottle<Textends()=>any>(fn: T,delay: number){
1223
lettimer: ReturnType<typeofsetTimeout>|undefined
1324

@@ -28,7 +39,7 @@ const throttledSend = throttle(() => {
2839
},SEND_DELAY)
2940

3041
exportfunctionsetupTelemetryRPC({ nuxt, options }: NuxtDevtoolsServerContext){
31-
if(options.telemetry!==false){
42+
if(options.telemetry!==false&&!isDoNotTrackEnabled()){
3243
// Only when global telemetry is enabled, the hook will be called
3344
nuxt.hook('telemetry:setup',(t)=>{
3445
telemetry=t
@@ -58,6 +69,9 @@ export function telemetryEvent(payload: object, immediate = false) {
5869
if(getOptions()?.behavior.telemetry===false)
5970
return
6071

72+
if(isDoNotTrackEnabled())
73+
return
74+
6175
telemetry.createEvent('devtools',payload)
6276

6377
if(immediate)

0 commit comments

Comments
 (0)