Skip to content

Commit 800a6f9

Browse files
chore(cli): switched analytics to use fetch instead of posthog-node
1 parent 64dbe39 commit 800a6f9

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

apps/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"handlebars": "^4.7.8",
6363
"jsonc-parser": "^3.3.1",
6464
"picocolors": "^1.1.1",
65-
"posthog-node": "^5.6.0",
6665
"trpc-cli": "^0.10.2",
6766
"ts-morph": "^26.0.0",
6867
"zod": "^4.0.14"

apps/cli/src/utils/analytics.ts

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PostHog } from "posthog-node";
21
import type { ProjectConfig } from "../types";
32
import { getLatestCLIVersion } from "./get-latest-cli-version";
43
import { isTelemetryEnabled } from "./telemetry";
@@ -7,35 +6,30 @@ const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
76
const POSTHOG_HOST = process.env.POSTHOG_HOST;
87

98
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;
1810

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;
2114

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+
};
2427

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),
3533
});
36-
} catch (_error) {
37-
// consola.debug("Analytics tracking failed:", error);
38-
} finally {
39-
await posthog.shutdown();
40-
}
34+
} catch (_error) {}
4135
}

bun.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"handlebars": "^4.7.8",
2929
"jsonc-parser": "^3.3.1",
3030
"picocolors": "^1.1.1",
31-
"posthog-node": "^5.6.0",
3231
"trpc-cli": "^0.10.2",
3332
"ts-morph": "^26.0.0",
3433
"zod": "^4.0.14",
@@ -2115,8 +2114,6 @@
21152114

21162115
"posthog-js": ["[email protected]", "", { "dependencies": { "core-js": "^3.38.1", "fflate": "^0.4.8", "preact": "^10.19.3", "web-vitals": "^4.2.4" }, "peerDependencies": { "@rrweb/types": "2.0.0-alpha.17", "rrweb-snapshot": "2.0.0-alpha.17" }, "optionalPeers": ["@rrweb/types", "rrweb-snapshot"] }, "sha512-Tx6CzS8MsGAQGPrQth5TbkGxGQgAY01SktNW773/KDmVOWiRVZq/WQF/MRJRiuFxJ7qjethZQi3aBWfWKdr1RA=="],
21172116

2118-
"posthog-node": ["[email protected]", "", {}, "sha512-MVXxKmqAYp2cPBrN1YMhnhYsJYIu6yc6wumbHz1dbo67wZBf2WtMm67Uh+4VCrp07049qierWlxQqz1W5zGDeg=="],
2119-
21202117
"preact": ["[email protected]", "", {}, "sha512-/DTYoB6mwwgPytiqQTh/7SFRL98ZdiD8Sk8zIUVOxtwq4oWcwrcd1uno9fE/zZmUaUrFNYzbH14CPebOz9tZQw=="],
21212118

21222119
"prelude-ls": ["[email protected]", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="],

0 commit comments

Comments
 (0)