-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy pathposthog.ts
31 lines (28 loc) · 1.15 KB
/
posthog.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { environment } from '@gauzy/config';
import { PosthogPlugin } from '@gauzy/plugin-posthog';
/**
* Initializes and configures the PostHog plugin for analytics and performance tracking.
*
* This function checks if PostHog tracking is enabled in the environment configuration.
* If enabled, it initializes the PostHog plugin with the specified settings.
* Otherwise, it logs a message indicating that PostHog was not initialized.
*
* @returns {typeof PosthogPlugin | null} The configured PostHog instance, or null if not initialized.
*/
export function initializePosthog(): typeof PosthogPlugin | null {
if (!environment.posthog?.posthogEnabled || !environment.posthog?.posthogKey) {
console.log('PostHog not initialized: Tracking is disabled or API key is missing');
return null;
}
// Configure PostHog
return PosthogPlugin.init({
apiKey: environment.posthog.posthogKey,
apiHost: environment.posthog.posthogHost || 'https://app.posthog.com',
enableErrorTracking: true,
flushInterval: environment.posthog.posthogFlushInterval || 10000,
flushAt: 20,
autocapture: true,
mock: false
});
}
export const PosthogAnalytics = initializePosthog();