mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 10:16:32 +02:00
23 lines
604 B
TypeScript
23 lines
604 B
TypeScript
import { waitUntil } from "@vercel/functions";
|
|
import { PostHog } from "posthog-node";
|
|
|
|
function PostHogClient() {
|
|
if (!process.env.NEXT_PUBLIC_POSTHOG_API_KEY) return null;
|
|
|
|
const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_API_KEY, {
|
|
host: process.env.NEXT_PUBLIC_POSTHOG_API_HOST,
|
|
flushAt: 1,
|
|
flushInterval: 0,
|
|
});
|
|
return posthogClient;
|
|
}
|
|
|
|
export const posthog = PostHogClient();
|
|
|
|
export function posthogApiHandler() {
|
|
try {
|
|
waitUntil(Promise.all([posthog?.shutdown()]));
|
|
} catch (error) {
|
|
console.error("Failed to flush PostHog events:", error);
|
|
}
|
|
}
|