-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-gatsby): add telemetry tracking (#28107)
- Loading branch information
Marvin Frachet
authored
Nov 17, 2020
1 parent
23b4137
commit f9838f7
Showing
5 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import fetch from "node-fetch" | ||
import uuidv4 from "uuid/v4" | ||
import { getConfigStore } from "./get-config-store" | ||
|
||
const store = getConfigStore() | ||
const gatsbyCliVersion = require(`../package.json`).version | ||
const analyticsApi = | ||
process.env.GATSBY_TELEMETRY_API || `https://analytics.gatsbyjs.com/events` | ||
|
||
const getMachineId = (): string => { | ||
let machineId = store.get(`telemetry.machineId`) | ||
|
||
if (typeof machineId !== `string`) { | ||
machineId = uuidv4() | ||
store.set(`telemetry.machineId`, machineId) | ||
} | ||
|
||
return machineId | ||
} | ||
|
||
export interface ITrackCliArgs { | ||
name?: string | ||
valueString?: string | ||
exitCode?: number | ||
valueStringArray?: Array<string> | ||
} | ||
|
||
export const trackCli = (eventType: string, args?: ITrackCliArgs): void => { | ||
fetch(analyticsApi, { | ||
method: `POST`, | ||
headers: { | ||
"content-type": `application/json`, | ||
"user-agent": `create-gatsby:${gatsbyCliVersion}`, | ||
}, | ||
body: JSON.stringify({ | ||
eventType, | ||
time: new Date(), | ||
sessionId: uuidv4(), | ||
machineId: getMachineId(), | ||
componentId: `create-gatsby`, | ||
componentVersion: 1, | ||
gatsbyCliVersion, | ||
...args, | ||
}), | ||
}).catch(() => {}) /* do nothing, it's telemetry */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
declare module "stream-filter" | ||
declare module "ansi-wordwrap" | ||
declare module 'uuid/v4'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import uuidv4 from "uuid" | ||
import uuidv4 from "uuid/v4" | ||
import os from "os" | ||
import { join } from "path" | ||
|
||
|