SurfSense/surfsense_web/lib/posthog/server.ts

20 lines
450 B
TypeScript
Raw Normal View History

2025-12-25 13:53:41 -08:00
import { PostHog } from "posthog-node";
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");
}
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
return posthogInstance;
2025-12-25 13:53:41 -08:00
}