mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-14 15:07:29 +02:00
📈 Posthog package (#1431)
This commit is contained in:
parent
0fc7d0a0c8
commit
a5da319d82
43 changed files with 189 additions and 133 deletions
23
packages/posthog/src/server/index.ts
Normal file
23
packages/posthog/src/server/index.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue