- Fix bootstrap-command test: mock ensureManagedWebRuntime to probe directly instead of requiring standalone build on disk - Add PostHog telemetry to CLI and web app with opt-out support - Add dench alias package (npm rejects name; kept for future use) - Bump version to 2.0.4 and publish to npm
44 lines
1005 B
TypeScript
44 lines
1005 B
TypeScript
import { createHash } from "node:crypto";
|
|
import os from "node:os";
|
|
import { PostHog } from "posthog-node";
|
|
|
|
const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY || "";
|
|
const POSTHOG_HOST = "https://us.i.posthog.com";
|
|
|
|
let client: PostHog | null = null;
|
|
|
|
function getAnonymousId(): string {
|
|
try {
|
|
const raw = `${os.hostname()}:${os.userInfo().username}`;
|
|
return createHash("sha256").update(raw).digest("hex").slice(0, 16);
|
|
} catch {
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
function ensureClient(): PostHog | null {
|
|
if (!POSTHOG_KEY) return null;
|
|
if (!client) {
|
|
client = new PostHog(POSTHOG_KEY, {
|
|
host: POSTHOG_HOST,
|
|
flushAt: 10,
|
|
flushInterval: 30_000,
|
|
});
|
|
}
|
|
return client;
|
|
}
|
|
|
|
export function trackServer(event: string, properties?: Record<string, unknown>): void {
|
|
const ph = ensureClient();
|
|
if (!ph) return;
|
|
|
|
ph.capture({
|
|
distinctId: getAnonymousId(),
|
|
event,
|
|
properties: {
|
|
...properties,
|
|
$process_person_profile: false,
|
|
},
|
|
});
|
|
}
|