mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 22:28:47 +00:00
49 lines
963 B
TypeScript
49 lines
963 B
TypeScript
/* eslint-disable */
|
|
import { PostHog } from 'posthog-js';
|
|
import { initPostHog } from '~/components/analytics/posthog';
|
|
import { ENV } from '~/components/utilities/config';
|
|
|
|
declare let TELEMETRY_CAPTURING_ENABLED: any;
|
|
|
|
class Capturer {
|
|
api: PostHog;
|
|
|
|
constructor() {
|
|
this.api = initPostHog()!;
|
|
}
|
|
|
|
capture(item: string) {
|
|
if (ENV == 'production' && TELEMETRY_CAPTURING_ENABLED) {
|
|
try {
|
|
this.api.capture(item);
|
|
} catch (error) {
|
|
console.error('PostHog', error);
|
|
}
|
|
}
|
|
}
|
|
|
|
identify(id: string) {
|
|
if (ENV == 'production' && TELEMETRY_CAPTURING_ENABLED) {
|
|
try {
|
|
this.api.identify(id);
|
|
} catch (error) {
|
|
console.error('PostHog', error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default class Telemetry {
|
|
static instance: Capturer;
|
|
|
|
constructor() {
|
|
if (!Telemetry.instance) {
|
|
Telemetry.instance = new Capturer();
|
|
}
|
|
}
|
|
|
|
getInstance() {
|
|
return Telemetry.instance;
|
|
}
|
|
}
|