// 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; }