MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / PostHogClient

Function PostHogClient

apps/web/src/lib/posthog.ts:6–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4let instance: PostHog | null = null;
5
6export default function PostHogClient(): Pick<
7 PostHog,
8 'capture' | 'isFeatureEnabled' | 'getFeatureFlag' | 'debug' | 'alias'
9> {
10 if (instance) return instance;
11
12 const key = getEnvVariable('NEXT_PUBLIC_POSTHOG_KEY') ?? '';
13 const isProduction = process.env.NODE_ENV === 'production';
14 if (!isProduction) {
15 return {
16 capture: () => {},
17 isFeatureEnabled: async () => false,
18 getFeatureFlag: async () => undefined,
19 debug: () => {},
20 alias: () => {},
21 };
22 }
23 // Single shared PostHog client for the process.
24 // Disabled outside production to avoid sending real events during tests/dev.
25 instance = new PostHog(isProduction ? key : key || 'disabled', {
26 host: 'https://us.i.posthog.com',
27 flushAt: 1,
28 flushInterval: 0,
29 disabled: !isProduction,
30 });
31
32 // if (!isProduction) {
33 // // eslint-disable-next-line @typescript-eslint/no-explicit-any
34 // (instance as any).capture = function (...args: any[]) {
35 // console.log('POSTHOG CAPTURE', ...args);
36 // };
37 // }
38
39 return instance;
40}
41
42/**
43 * Flushes buffered events. A no-op outside production, where no shared

Callers 15

SurveyCreditsFunction · 0.85
saveFingerprintsFunction · 0.85
index.tsFile · 0.85
server.tsFile · 0.85
processUsage.tsFile · 0.85

Calls 1

getEnvVariableFunction · 0.90

Tested by

no test coverage detected