chore(cli): switched analytics to use fetch instead of posthog-node

This commit is contained in:
Aman Varshney
2025-08-05 15:28:12 +05:30
parent 64dbe39b61
commit 800a6f9a63
3 changed files with 23 additions and 33 deletions

View File

@@ -62,7 +62,6 @@
"handlebars": "^4.7.8",
"jsonc-parser": "^3.3.1",
"picocolors": "^1.1.1",
"posthog-node": "^5.6.0",
"trpc-cli": "^0.10.2",
"ts-morph": "^26.0.0",
"zod": "^4.0.14"

View File

@@ -1,4 +1,3 @@
import { PostHog } from "posthog-node";
import type { ProjectConfig } from "../types";
import { getLatestCLIVersion } from "./get-latest-cli-version";
import { isTelemetryEnabled } from "./telemetry";
@@ -7,35 +6,30 @@ const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
const POSTHOG_HOST = process.env.POSTHOG_HOST;
export async function trackProjectCreation(config: ProjectConfig) {
const posthog = new PostHog(POSTHOG_API_KEY, {
host: POSTHOG_HOST,
flushAt: 1,
flushInterval: 0,
privacyMode: true,
disableGeoip: true,
disabled: !isTelemetryEnabled(),
});
if (!isTelemetryEnabled()) return;
const sessionId = `cli_${crypto.randomUUID().replace(/-/g, "")}`;
// biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties
const { projectName, projectDir, relativePath, ...safeConfig } = config;
const payload = {
api_key: POSTHOG_API_KEY,
event: "project_created",
properties: {
...safeConfig,
cli_version: getLatestCLIVersion(),
node_version: process.version,
platform: process.platform,
$ip: null,
},
distinct_id: sessionId,
};
try {
const sessionId = `cli_${crypto.randomUUID().replace(/-/g, "")}`;
// biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties
const { projectName, projectDir, relativePath, ...safeConfig } = config;
posthog.capture({
distinctId: sessionId,
event: "project_created",
properties: {
...safeConfig,
cli_version: getLatestCLIVersion(),
node_version: process.version,
platform: process.platform,
$ip: null,
},
await fetch(`${POSTHOG_HOST}/capture`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
} catch (_error) {
// consola.debug("Analytics tracking failed:", error);
} finally {
await posthog.shutdown();
}
} catch (_error) {}
}