-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathposthog.ts
More file actions
34 lines (29 loc) · 883 Bytes
/
posthog.ts
File metadata and controls
34 lines (29 loc) · 883 Bytes
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
32
33
34
import { env, SOURCEBOT_VERSION } from "@sourcebot/shared";
import { PostHog } from 'posthog-node';
import { PosthogEvent, PosthogEventMap } from './posthogEvents.js';
let posthog: PostHog | undefined = undefined;
if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: "https://us.i.posthog.com",
}
);
}
export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}
posthog?.capture({
distinctId: env.SOURCEBOT_INSTALL_ID,
event: event,
properties: {
...properties,
sourcebot_version: SOURCEBOT_VERSION,
install_id: env.SOURCEBOT_INSTALL_ID,
},
});
}
export async function shutdownPosthog() {
await posthog?.shutdown();
}