Elffuss BraidHub

kikocis/continue public

main · 1.0 KiBRawPermalink
1import { Analytics } from "@continuedev/config-types";
2
3import {
4 ControlPlaneProxyInfo,
5 IAnalyticsProvider,
6} from "./IAnalyticsProvider.js";
7
8export default class PostHogAnalyticsProvider implements IAnalyticsProvider {
9 client?: any;
10 uniqueId?: string;
11
12 async capture(
13 event: string,
14 properties: { [key: string]: any },
15 ): Promise<void> {
16 this.client?.capture({
17 distinctId: this.uniqueId,
18 event,
19 properties,
20 });
21 }
22
23 async setup(
24 config: Analytics,
25 uniqueId: string,
26 controlPlaneProxyInfo?: ControlPlaneProxyInfo,
27 ): Promise<void> {
28 if (!config || !config.clientKey || !config.url) {
29 this.client = undefined;
30 } else {
31 try {
32 this.uniqueId = uniqueId;
33
34 const { PostHog } = await import("posthog-node");
35 this.client = new PostHog(config.clientKey, {
36 host: config.url,
37 });
38 } catch (e) {
39 console.error(`Failed to setup telemetry: ${e}`);
40 }
41 }
42 }
43
44 async shutdown(): Promise<void> {}
45}