mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-21 21:09:49 +08:00
Some checks are pending
Runs E2E API Tests / build (20.x) (push) Waiting to run
Runs E2E API Tests / build (22.x) (push) Waiting to run
Lint & build / lint_and_build (20.x) (push) Waiting to run
Lint & build / lint_and_build (22.x) (push) Waiting to run
TOC Generator / TOC Generator (push) Waiting to run
17 lines
551 B
TypeScript
17 lines
551 B
TypeScript
import { getEnvVariable } from '@stackframe/stack-shared/dist/utils/env';
|
|
import { PostHog } from 'posthog-node';
|
|
|
|
export default async function withPostHog<T>(callback: (posthog: PostHog) => Promise<T>) {
|
|
const postHogKey = getEnvVariable("NEXT_PUBLIC_POSTHOG_KEY", "phc_vIUFi0HzHo7oV26OsaZbUASqxvs8qOmap1UBYAutU4k");
|
|
const posthogClient = new PostHog(postHogKey, {
|
|
host: "https://eu.i.posthog.com",
|
|
flushAt: 1,
|
|
flushInterval: 0
|
|
});
|
|
try {
|
|
await callback(posthogClient);
|
|
} finally {
|
|
await posthogClient.shutdown();
|
|
}
|
|
}
|