continue-custom/core/control-plane/analytics/PostHogAnalyticsProvider.ts
Nate Sesti 8fed0cb985
Convert core/ to NodeNext (#1877)
* convert to nodenext in core

* experimental vm modules

* use imports

* a few ts-ignores

---------

Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
2024-07-30 19:04:30 -07:00

37 lines
937 B
TypeScript

import { Analytics } from "@continuedev/config-types";
import { IAnalyticsProvider } from "./IAnalyticsProvider.js";
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> {}
}