mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-13 04:45:19 +00:00
31 lines
No EOL
739 B
TypeScript
31 lines
No EOL
739 B
TypeScript
import { PostHog } from 'posthog-node';
|
|
import { PosthogEvent, PosthogEventMap } from './posthogEvents.js';
|
|
import { env } from './env.js';
|
|
|
|
let posthog: PostHog | undefined = undefined;
|
|
|
|
if (env.POSTHOG_PAPIK) {
|
|
posthog = new PostHog(
|
|
env.POSTHOG_PAPIK,
|
|
{
|
|
host: env.POSTHOG_HOST,
|
|
}
|
|
);
|
|
}
|
|
|
|
export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
|
|
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
|
|
return;
|
|
}
|
|
|
|
posthog?.capture({
|
|
distinctId: env.SOURCEBOT_INSTALL_ID,
|
|
event: event,
|
|
properties: {
|
|
...properties,
|
|
sourcebot_version: env.SOURCEBOT_VERSION,
|
|
},
|
|
});
|
|
}
|
|
|
|
await posthog?.shutdown(); |