mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
chore(cli): switched analytics to use fetch instead of posthog-node
This commit is contained in:
@@ -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) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user