Files
classroomio/apps/dashboard/src/lib/utils/services/posthog/index.ts
T

26 lines
761 B
TypeScript
Raw Normal View History

2023-10-30 06:04:53 +00:00
import { dev } from '$app/environment';
2026-03-09 11:18:22 +01:00
import { licenseApi } from '$features/license/api/license.svelte';
2023-10-30 06:04:53 +00:00
import posthog from 'posthog-js';
2026-03-09 11:18:22 +01:00
const hasNoTracking = () => licenseApi.hasAccess('no-tracking');
2024-04-07 22:01:36 +01:00
export const capturePosthogEvent = (event: string, properties?: Record<string, unknown>): void => {
2026-03-09 11:18:22 +01:00
if (dev || hasNoTracking()) return;
2023-10-30 06:04:53 +00:00
posthog.capture(event, properties);
};
2024-04-07 22:01:36 +01:00
export const identifyPosthogUser = (id: string, properties?: Record<string, unknown>): void => {
2026-03-09 11:18:22 +01:00
if (dev || hasNoTracking()) return;
2023-10-30 06:04:53 +00:00
posthog.identify(id, properties);
};
export const initPosthog = (): void => {
2026-03-09 11:18:22 +01:00
if (dev || hasNoTracking()) return;
2023-10-30 06:04:53 +00:00
posthog.init('phc_JfdHOZ6v0cVlGELBYx1Tmoen2nxNOrAzvgvrPA6Ksov', {
api_host: 'https://eu.posthog.com'
});
};