2021-09-16 18:12:51 +02:00
|
|
|
import { POSTHOG_API_KEY, POSTHOG_URL } from "../Enum/EnvironmentVariable";
|
2021-10-08 11:53:45 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
declare let window: any;
|
2021-09-15 11:50:25 +02:00
|
|
|
|
|
|
|
class AnalyticsClient {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-11-24 17:02:11 +01:00
|
|
|
private posthogPromise: Promise<any> | undefined;
|
2021-09-15 11:50:25 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
if (POSTHOG_API_KEY && POSTHOG_URL) {
|
2021-09-16 18:12:51 +02:00
|
|
|
this.posthogPromise = import("posthog-js").then(({ default: posthog }) => {
|
2021-09-15 11:50:25 +02:00
|
|
|
posthog.init(POSTHOG_API_KEY, { api_host: POSTHOG_URL, disable_cookie: true });
|
2021-10-08 11:53:45 +02:00
|
|
|
//the posthog toolbar need a reference in window to be able to work
|
|
|
|
window.posthog = posthog;
|
2021-09-15 11:50:25 +02:00
|
|
|
return posthog;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 16:14:55 +02:00
|
|
|
identifyUser(uuid: string, email: string | null) {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.identify(uuid, { uuid, email, wa: true });
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
loggedWithSso() {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-logged-sso");
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
loggedWithToken() {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-logged-token");
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
|
2021-09-30 16:14:55 +02:00
|
|
|
enteredRoom(roomId: string, roomGroup: string | null) {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("$pageView", { roomId, roomGroup });
|
|
|
|
posthog.capture("enteredRoom");
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
openedMenu() {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-opened-menu");
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
launchEmote(emote: string) {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-emote-launch", { emote });
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enteredJitsi(roomName: string, roomId: string) {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-entered-jitsi", { roomName, roomId });
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
2021-11-18 11:39:56 +01:00
|
|
|
|
|
|
|
validationName() {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-name-validation");
|
|
|
|
});
|
2021-11-18 11:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
validationWoka(scene: string) {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-woka-validation", { scene });
|
|
|
|
});
|
2021-11-18 11:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
validationVideo() {
|
2021-11-24 17:02:11 +01:00
|
|
|
this.posthogPromise?.then((posthog) => {
|
|
|
|
posthog.capture("wa-video-validation");
|
|
|
|
});
|
2021-09-15 11:50:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export const analyticsClient = new AnalyticsClient();
|