1
- import { PostHog } from "posthog-node" ;
2
1
import type { ProjectConfig } from "../types" ;
3
2
import { getLatestCLIVersion } from "./get-latest-cli-version" ;
4
3
import { isTelemetryEnabled } from "./telemetry" ;
@@ -7,35 +6,30 @@ const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
7
6
const POSTHOG_HOST = process . env . POSTHOG_HOST ;
8
7
9
8
export async function trackProjectCreation ( config : ProjectConfig ) {
10
- const posthog = new PostHog ( POSTHOG_API_KEY , {
11
- host : POSTHOG_HOST ,
12
- flushAt : 1 ,
13
- flushInterval : 0 ,
14
- privacyMode : true ,
15
- disableGeoip : true ,
16
- disabled : ! isTelemetryEnabled ( ) ,
17
- } ) ;
9
+ if ( ! isTelemetryEnabled ( ) ) return ;
18
10
19
- try {
20
- const sessionId = `cli_${ crypto . randomUUID ( ) . replace ( / - / g, "" ) } ` ;
11
+ const sessionId = `cli_${ crypto . randomUUID ( ) . replace ( / - / g, "" ) } ` ;
12
+ // biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties
13
+ const { projectName, projectDir, relativePath, ...safeConfig } = config ;
21
14
22
- // biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties
23
- const { projectName, projectDir, relativePath, ...safeConfig } = config ;
15
+ const payload = {
16
+ api_key : POSTHOG_API_KEY ,
17
+ event : "project_created" ,
18
+ properties : {
19
+ ...safeConfig ,
20
+ cli_version : getLatestCLIVersion ( ) ,
21
+ node_version : process . version ,
22
+ platform : process . platform ,
23
+ $ip : null ,
24
+ } ,
25
+ distinct_id : sessionId ,
26
+ } ;
24
27
25
- posthog . capture ( {
26
- distinctId : sessionId ,
27
- event : "project_created" ,
28
- properties : {
29
- ...safeConfig ,
30
- cli_version : getLatestCLIVersion ( ) ,
31
- node_version : process . version ,
32
- platform : process . platform ,
33
- $ip : null ,
34
- } ,
28
+ try {
29
+ await fetch ( `${ POSTHOG_HOST } /capture` , {
30
+ method : "POST" ,
31
+ headers : { "Content-Type" : "application/json" } ,
32
+ body : JSON . stringify ( payload ) ,
35
33
} ) ;
36
- } catch ( _error ) {
37
- // consola.debug("Analytics tracking failed:", error);
38
- } finally {
39
- await posthog . shutdown ( ) ;
40
- }
34
+ } catch ( _error ) { }
41
35
}
0 commit comments