-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
79 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { randomUUID } from "node:crypto"; | ||
import { GA4_URL } from "./utils/constants.js"; | ||
import { getOS } from "./utils/helpers.js"; | ||
import { Selections } from "./types.js"; | ||
|
||
export const recordTelemetry = async (selection: Selections) => { | ||
try { | ||
const telemetry = { | ||
client_id: randomUUID(), // We generate a random client id for each request | ||
user_id: randomUUID(), // can we find a better way of identifying each CLI user? | ||
timestamp_micros: (Date.now() * 1000).toString(), | ||
events: [ | ||
{ | ||
name: "wizard_command", | ||
params: { | ||
command: "npx create-aptos-dapp", // TODO make it generic once --example is introduced | ||
project_name: selection.projectName, | ||
template: selection.template.name, | ||
network: selection.network, | ||
os: getOS(), | ||
}, | ||
}, | ||
], | ||
}; | ||
const res = await fetch(GA4_URL, { | ||
method: "POST", | ||
body: JSON.stringify(telemetry), | ||
headers: { "content-type": "application/json" }, | ||
}); | ||
// this is helpful when using GA4_URL_DEBUG to debug GA4 query. GA4_URL does not return any body response back | ||
if (res.body) { | ||
const resJson = await res.json(); | ||
console.log("ga4 debug response", resJson); | ||
} | ||
} catch (err: any) { | ||
console.log("could not send analytics", err); | ||
} | ||
}; |
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 |
---|---|---|
|
@@ -16,4 +16,5 @@ export type Selections = { | |
projectName: string; | ||
template: Template; | ||
network: Network; | ||
analytics: boolean; | ||
}; |
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,5 @@ | ||
// GA4 | ||
export const GA_MEASURMENT_ID = "G-QCE2R28N2J"; | ||
export const GA_CLIENT_ID = "Xhptd45qQKiPALmqqRheqg"; | ||
export const GA4_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASURMENT_ID}&api_secret=${GA_CLIENT_ID}`; | ||
export const GA4_URL_DEBUG = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASURMENT_ID}&api_secret=${GA_CLIENT_ID}`; |
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