Skip to content

Commit e24ad92

Browse files
committed
fix: make gatsby-telemetry no-op
1 parent 02b7aac commit e24ad92

File tree

10 files changed

+105
-659
lines changed

10 files changed

+105
-659
lines changed

Diff for: packages/gatsby-telemetry/package.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,9 @@
99
"dependencies": {
1010
"@babel/code-frame": "^7.18.6",
1111
"@babel/runtime": "^7.20.13",
12-
"@turist/fetch": "^7.2.0",
13-
"@turist/time": "^0.0.2",
14-
"boxen": "^5.1.2",
15-
"configstore": "^5.0.1",
1612
"fs-extra": "^11.2.0",
1713
"gatsby-core-utils": "^4.14.0-next.2",
18-
"git-up": "^7.0.0",
19-
"is-docker": "^2.2.1",
20-
"lodash": "^4.17.21",
21-
"node-fetch": "^2.6.11"
14+
"git-up": "^7.0.0"
2215
},
2316
"devDependencies": {
2417
"@babel/cli": "^7.20.7",
@@ -46,7 +39,6 @@
4639
"scripts": {
4740
"build": "babel src --out-dir lib --ignore \"**/__tests__\",\"**/__mocks__\" --extensions \".ts,.js\"",
4841
"prepare": "cross-env NODE_ENV=production npm run build && npm run typegen",
49-
"postinstall": "node src/postinstall.js || true",
5042
"typegen": "rimraf --glob \"lib/**/*.d.ts\" && tsc --emitDeclarationOnly --declaration --declarationDir lib/",
5143
"watch": "babel -w src --out-dir lib --ignore \"**/__tests__\",\"**/__mocks__\" --extensions \".ts,.js\""
5244
},

Diff for: packages/gatsby-telemetry/src/__tests__/telemetry.ts

-182
This file was deleted.

Diff for: packages/gatsby-telemetry/src/create-flush.ts

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
import { isCI } from "gatsby-core-utils"
2-
const { join } = require(`path`)
3-
const { fork, spawnSync } = require(`child_process`)
4-
import time, { TimeUnit } from "@turist/time"
5-
61
export function createFlush(isTrackingEnabled: boolean): () => Promise<void> {
7-
return async function flush(): Promise<void> {
8-
if (!isTrackingEnabled) {
9-
return
10-
}
11-
12-
if (isCI()) {
13-
spawnSync(process.execPath, [join(__dirname, `send.js`)], {
14-
execArgv: [],
15-
timeout: time(1, TimeUnit.Minute),
16-
})
17-
return
18-
}
19-
// Submit events on background with out blocking the main process
20-
// nor relying on it's life cycle
21-
const forked = fork(join(__dirname, `send.js`), {
22-
detached: true,
23-
stdio: `ignore`,
24-
execArgv: [],
25-
})
26-
forked.unref()
27-
}
2+
return async function flush(): Promise<void> {}
283
}

Diff for: packages/gatsby-telemetry/src/event-storage.ts

+10-55
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import path from "path"
2-
import Configstore from "configstore"
3-
import createFetch from "@turist/fetch"
42
import { Store } from "./store"
53
import { ensureDirSync } from "fs-extra"
6-
import { isTruthy } from "gatsby-core-utils"
7-
import { InMemoryConfigStore } from "./in-memory-store"
84

9-
const fetch = createFetch()
5+
import { InMemoryConfigStore } from "./in-memory-store"
106

117
/* The events data collection is a spooled process that
128
* buffers events to a local fs based buffer
@@ -15,20 +11,15 @@ const fetch = createFetch()
1511
* to continue even when working offline.
1612
*/
1713
export class EventStorage {
18-
analyticsApi =
19-
process.env.GATSBY_TELEMETRY_API || `https://analytics.gatsbyjs.com/events`
20-
config: Configstore | InMemoryConfigStore
14+
analyticsApi = process.env.GATSBY_TELEMETRY_API
15+
config: InMemoryConfigStore
2116
store: Store
2217
verbose: boolean
2318
debugEvents: boolean
2419
disabled: boolean
2520

2621
constructor() {
27-
try {
28-
this.config = new Configstore(`gatsby`, {}, { globalConfigPath: true })
29-
} catch (e) {
30-
this.config = new InMemoryConfigStore()
31-
}
22+
this.config = new InMemoryConfigStore()
3223

3324
const baseDir = path.dirname(this.config.path)
3425

@@ -39,59 +30,23 @@ export class EventStorage {
3930
}
4031

4132
this.store = new Store(baseDir)
42-
this.verbose = isTruthy(process.env.GATSBY_TELEMETRY_VERBOSE)
43-
this.debugEvents = isTruthy(process.env.GATSBY_TELEMETRY_DEBUG)
44-
this.disabled = isTruthy(process.env.GATSBY_TELEMETRY_DISABLED)
33+
this.verbose = false
34+
this.debugEvents = false
35+
this.disabled = true
4536
}
4637

4738
isTrackingDisabled(): boolean {
4839
return this.disabled
4940
}
5041

51-
addEvent(event: unknown): void {
52-
if (this.disabled) {
53-
return
54-
}
55-
56-
const eventString = JSON.stringify(event)
57-
58-
if (this.debugEvents || this.verbose) {
59-
console.log(`Captured event:`, JSON.parse(eventString))
60-
61-
if (this.debugEvents) {
62-
// Bail because we don't want to send debug events
63-
return
64-
}
65-
}
66-
67-
this.store.appendToBuffer(eventString + `\n`)
68-
}
42+
addEvent(event: unknown): void {}
6943

7044
async sendEvents(): Promise<boolean> {
71-
return this.store.startFlushEvents(async (eventsData: string) => {
72-
const events = eventsData
73-
.split(`\n`)
74-
.filter(e => e && e.length > 2) // drop empty lines
75-
.map(e => JSON.parse(e))
76-
77-
return this.submitEvents(events)
78-
})
45+
return true
7946
}
8047

8148
async submitEvents(events: unknown): Promise<boolean> {
82-
try {
83-
const res = await fetch(this.analyticsApi, {
84-
method: `POST`,
85-
headers: {
86-
"content-type": `application/json`,
87-
"user-agent": this.getUserAgent(),
88-
},
89-
body: JSON.stringify(events),
90-
})
91-
return res.ok
92-
} catch (e) {
93-
return false
94-
}
49+
return true
9550
}
9651

9752
getUserAgent(): string {

0 commit comments

Comments
 (0)