2025-12-25 13:53:41 -08:00
|
|
|
import { PostHog } from "posthog-node";
|
|
|
|
|
|
2026-03-12 01:28:39 -07:00
|
|
|
let posthogInstance: PostHog | null = null;
|
|
|
|
|
|
2025-12-25 13:53:41 -08:00
|
|
|
export default function PostHogClient() {
|
|
|
|
|
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) {
|
|
|
|
|
throw new Error("NEXT_PUBLIC_POSTHOG_KEY is not set");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 01:28:39 -07:00
|
|
|
if (!posthogInstance) {
|
|
|
|
|
posthogInstance = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
|
|
|
|
|
host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
|
|
|
|
flushAt: 1,
|
|
|
|
|
flushInterval: 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-25 13:53:41 -08:00
|
|
|
|
2026-03-12 01:28:39 -07:00
|
|
|
return posthogInstance;
|
2025-12-25 13:53:41 -08:00
|
|
|
}
|