continue/core/control-plane/analytics/PostHogAnalyticsProvider.ts

38 lines
934 B
TypeScript

import { Analytics } from "@continuedev/config-types";
import { IAnalyticsProvider } from "./IAnalyticsProvider";
export default class PostHogAnalyticsProvider implements IAnalyticsProvider {
client?: any;
uniqueId?: string;
async capture(
event: string,
properties: { [key: string]: any },
): Promise<void> {
this.client?.capture({
distinctId: this.uniqueId,
event,
properties,
});
}
async setup(config: Analytics, uniqueId: string): Promise<void> {
if (!config || !config.clientKey || !config.url) {
this.client = undefined;
} else {
try {
this.uniqueId = uniqueId;
const { PostHog } = await import("posthog-node");
this.client = new PostHog(config.clientKey, {
host: config.url,
});
} catch (e) {
console.error(`Failed to setup telemetry: ${e}`);
}
}
}
async shutdown(): Promise<void> {}
}