Posthog integration

This commit is contained in:
2025-08-11 08:54:45 +02:00
parent 878dbc63f7
commit 1179b406b8
7 changed files with 322 additions and 76 deletions

21
lib/posthog.js Normal file
View File

@@ -0,0 +1,21 @@
// lib/posthog.ts
import { PostHog } from "posthog-node";
export function PostHogClient() {
// Server-Keys verwenden (ohne NEXT_PUBLIC_)
const key = process.env.POSTHOG_API_KEY;
const host = process.env.POSTHOG_HOST ?? "https://us.i.posthog.com";
if (!key) {
// Fail fast sonst sendest du stumm nichts
throw new Error("POSTHOG_API_KEY ist nicht gesetzt (serverseitige Env).");
}
const client = new PostHog(key, {
host,
flushAt: 1,
flushInterval: 0,
});
return client;
}