Merge pull request #1458 from thecodingmachine/posthog
FEATURE: added posthog as new analytics tool
This commit is contained in:
commit
483191c521
@ -75,6 +75,9 @@
|
|||||||
"UPLOADER_URL": "//uploader-"+url,
|
"UPLOADER_URL": "//uploader-"+url,
|
||||||
"ADMIN_URL": "//"+url,
|
"ADMIN_URL": "//"+url,
|
||||||
"JITSI_URL": env.JITSI_URL,
|
"JITSI_URL": env.JITSI_URL,
|
||||||
|
#POSTHOG
|
||||||
|
"POSTHOG_API_KEY": if namespace == "master" then env.POSTHOG_API_KEY else "",
|
||||||
|
"POSTHOG_URL": if namespace == "master" then env.POSTHOG_URL else "",
|
||||||
"SECRET_JITSI_KEY": env.SECRET_JITSI_KEY,
|
"SECRET_JITSI_KEY": env.SECRET_JITSI_KEY,
|
||||||
"TURN_SERVER": "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443",
|
"TURN_SERVER": "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443",
|
||||||
"JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false",
|
"JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false",
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
"phaser": "^3.54.0",
|
"phaser": "^3.54.0",
|
||||||
"phaser-animated-tiles": "workadventure/phaser-animated-tiles#da68bbededd605925621dd4f03bd27e69284b254",
|
"phaser-animated-tiles": "workadventure/phaser-animated-tiles#da68bbededd605925621dd4f03bd27e69284b254",
|
||||||
"phaser3-rex-plugins": "^1.1.42",
|
"phaser3-rex-plugins": "^1.1.42",
|
||||||
|
"posthog-js": "^1.13.12",
|
||||||
"queue-typescript": "^1.0.1",
|
"queue-typescript": "^1.0.1",
|
||||||
"quill": "1.3.6",
|
"quill": "1.3.6",
|
||||||
"quill-delta-to-html": "^0.12.0",
|
"quill-delta-to-html": "^0.12.0",
|
||||||
|
61
front/src/Administration/AnalyticsClient.ts
Normal file
61
front/src/Administration/AnalyticsClient.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import {POSTHOG_API_KEY, POSTHOG_URL} from "../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
|
class AnalyticsClient {
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
private posthogPromise: Promise<any>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
if (POSTHOG_API_KEY && POSTHOG_URL) {
|
||||||
|
this.posthogPromise = import('posthog-js').then(({default: posthog}) => {
|
||||||
|
posthog.init(POSTHOG_API_KEY, { api_host: POSTHOG_URL, disable_cookie: true });
|
||||||
|
return posthog;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.posthogPromise = Promise.reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
identifyUser(uuid: string) {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.identify(uuid, { uuid, wa: true });
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
loggedWithSso() {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.capture('wa-logged-sso');
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
loggedWithToken() {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.capture('wa-logged-token');
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
enteredRoom(roomId: string) {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.capture('$pageView', {roomId});
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
openedMenu() {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.capture('wa-opened-menu');
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
launchEmote(emote: string) {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.capture('wa-emote-launch', {emote});
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
enteredJitsi(roomName: string, roomId: string) {
|
||||||
|
this.posthogPromise.then(posthog => {
|
||||||
|
posthog.capture('wa-entered-jitsi', {roomName, roomId});
|
||||||
|
}).catch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const analyticsClient = new AnalyticsClient();
|
@ -9,6 +9,7 @@ import { Room } from "./Room";
|
|||||||
import { _ServiceWorker } from "../Network/ServiceWorker";
|
import { _ServiceWorker } from "../Network/ServiceWorker";
|
||||||
import { loginSceneVisibleIframeStore } from "../Stores/LoginSceneStore";
|
import { loginSceneVisibleIframeStore } from "../Stores/LoginSceneStore";
|
||||||
import { userIsConnected } from "../Stores/MenuStore";
|
import { userIsConnected } from "../Stores/MenuStore";
|
||||||
|
import {analyticsClient} from "../Administration/AnalyticsClient";
|
||||||
|
|
||||||
class ConnectionManager {
|
class ConnectionManager {
|
||||||
private localUser!: LocalUser;
|
private localUser!: LocalUser;
|
||||||
@ -93,6 +94,7 @@ class ConnectionManager {
|
|||||||
this._currentRoom = await Room.createRoom(new URL(localUserStore.getLastRoomUrl()));
|
this._currentRoom = await Room.createRoom(new URL(localUserStore.getLastRoomUrl()));
|
||||||
try {
|
try {
|
||||||
await this.checkAuthUserConnexion();
|
await this.checkAuthUserConnexion();
|
||||||
|
analyticsClient.loggedWithSso();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
this.loadOpenIDScreen();
|
this.loadOpenIDScreen();
|
||||||
@ -109,6 +111,7 @@ class ConnectionManager {
|
|||||||
this.authToken = data.authToken;
|
this.authToken = data.authToken;
|
||||||
localUserStore.saveUser(this.localUser);
|
localUserStore.saveUser(this.localUser);
|
||||||
localUserStore.setAuthToken(this.authToken);
|
localUserStore.setAuthToken(this.authToken);
|
||||||
|
analyticsClient.loggedWithToken();
|
||||||
|
|
||||||
const roomUrl = data.roomUrl;
|
const roomUrl = data.roomUrl;
|
||||||
|
|
||||||
@ -184,6 +187,9 @@ class ConnectionManager {
|
|||||||
if (this._currentRoom == undefined) {
|
if (this._currentRoom == undefined) {
|
||||||
return Promise.reject(new Error("Invalid URL"));
|
return Promise.reject(new Error("Invalid URL"));
|
||||||
}
|
}
|
||||||
|
if (this.localUser) {
|
||||||
|
analyticsClient.identifyUser(this.localUser.uuid)
|
||||||
|
}
|
||||||
|
|
||||||
this.serviceWorker = new _ServiceWorker();
|
this.serviceWorker = new _ServiceWorker();
|
||||||
return Promise.resolve(this._currentRoom);
|
return Promise.resolve(this._currentRoom);
|
||||||
|
@ -20,6 +20,8 @@ export const DISPLAY_TERMS_OF_USE = process.env.DISPLAY_TERMS_OF_USE == "true";
|
|||||||
export const NODE_ENV = process.env.NODE_ENV || "development";
|
export const NODE_ENV = process.env.NODE_ENV || "development";
|
||||||
export const CONTACT_URL = process.env.CONTACT_URL || undefined;
|
export const CONTACT_URL = process.env.CONTACT_URL || undefined;
|
||||||
export const PROFILE_URL = process.env.PROFILE_URL || undefined;
|
export const PROFILE_URL = process.env.PROFILE_URL || undefined;
|
||||||
|
export const POSTHOG_API_KEY: string = process.env.POSTHOG_API_KEY as string || '';
|
||||||
|
export const POSTHOG_URL = process.env.POSTHOG_URL || undefined;
|
||||||
|
|
||||||
export const isMobile = (): boolean => window.innerWidth <= 800 || window.innerHeight <= 600;
|
export const isMobile = (): boolean => window.innerWidth <= 800 || window.innerHeight <= 600;
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore";
|
|||||||
import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager";
|
import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager";
|
||||||
import { GameMapPropertiesListener } from "./GameMapPropertiesListener";
|
import { GameMapPropertiesListener } from "./GameMapPropertiesListener";
|
||||||
import type { RadialMenuItem } from "../Components/RadialMenu";
|
import type { RadialMenuItem } from "../Components/RadialMenu";
|
||||||
|
import {analyticsClient} from "../../Administration/AnalyticsClient";
|
||||||
|
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface | null;
|
initPosition: PointInterface | null;
|
||||||
@ -426,6 +427,7 @@ export class GameScene extends DirtyScene {
|
|||||||
|
|
||||||
gameManager.gameSceneIsCreated(this);
|
gameManager.gameSceneIsCreated(this);
|
||||||
urlManager.pushRoomIdToUrl(this.room);
|
urlManager.pushRoomIdToUrl(this.room);
|
||||||
|
analyticsClient.enteredRoom(this.room.id);
|
||||||
|
|
||||||
if (touchScreenManager.supportTouchScreen) {
|
if (touchScreenManager.supportTouchScreen) {
|
||||||
this.pinchManager = new PinchManager(this);
|
this.pinchManager = new PinchManager(this);
|
||||||
@ -1440,6 +1442,7 @@ ${escapedMessage}
|
|||||||
});
|
});
|
||||||
this.CurrentPlayer.on(requestEmoteEventName, (emoteKey: string) => {
|
this.CurrentPlayer.on(requestEmoteEventName, (emoteKey: string) => {
|
||||||
this.connection?.emitEmoteEvent(emoteKey);
|
this.connection?.emitEmoteEvent(emoteKey);
|
||||||
|
analyticsClient.launchEmote(emoteKey);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof TextureError) {
|
if (err instanceof TextureError) {
|
||||||
@ -1807,6 +1810,7 @@ ${escapedMessage}
|
|||||||
jitsiFactory.start(roomName, this.playerName, jwt, jitsiConfig, jitsiInterfaceConfig, jitsiUrl, jitsiWidth);
|
jitsiFactory.start(roomName, this.playerName, jwt, jitsiConfig, jitsiInterfaceConfig, jitsiUrl, jitsiWidth);
|
||||||
this.connection?.setSilent(true);
|
this.connection?.setSilent(true);
|
||||||
mediaManager.hideGameOverlay();
|
mediaManager.hideGameOverlay();
|
||||||
|
analyticsClient.enteredJitsi(roomName, this.room.id);
|
||||||
|
|
||||||
//permit to stop jitsi when user close iframe
|
//permit to stop jitsi when user close iframe
|
||||||
mediaManager.addTriggerCloseJitsiFrameButton("close-jitsi", () => {
|
mediaManager.addTriggerCloseJitsiFrameButton("close-jitsi", () => {
|
||||||
|
@ -2,11 +2,14 @@ import { get, writable } from "svelte/store";
|
|||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
import { userIsAdminStore } from "./GameStore";
|
import { userIsAdminStore } from "./GameStore";
|
||||||
import { CONTACT_URL } from "../Enum/EnvironmentVariable";
|
import { CONTACT_URL } from "../Enum/EnvironmentVariable";
|
||||||
|
import {analyticsClient} from "../Administration/AnalyticsClient";
|
||||||
|
|
||||||
export const menuIconVisiblilityStore = writable(false);
|
export const menuIconVisiblilityStore = writable(false);
|
||||||
export const menuVisiblilityStore = writable(false);
|
export const menuVisiblilityStore = writable(false);
|
||||||
|
menuVisiblilityStore.subscribe((value) => {
|
||||||
|
if (value) analyticsClient.openedMenu();
|
||||||
|
})
|
||||||
export const menuInputFocusStore = writable(false);
|
export const menuInputFocusStore = writable(false);
|
||||||
export const loginUrlStore = writable(false);
|
|
||||||
export const userIsConnected = writable(false);
|
export const userIsConnected = writable(false);
|
||||||
|
|
||||||
let warningContainerTimeout: Timeout | null = null;
|
let warningContainerTimeout: Timeout | null = null;
|
||||||
|
@ -23,9 +23,9 @@ import { Game } from "./Phaser/Game/Game";
|
|||||||
import App from "./Components/App.svelte";
|
import App from "./Components/App.svelte";
|
||||||
import { HtmlUtils } from "./WebRtc/HtmlUtils";
|
import { HtmlUtils } from "./WebRtc/HtmlUtils";
|
||||||
import WebGLRenderer = Phaser.Renderer.WebGL.WebGLRenderer;
|
import WebGLRenderer = Phaser.Renderer.WebGL.WebGLRenderer;
|
||||||
|
import {analyticsClient} from "./Administration/AnalyticsClient";
|
||||||
|
|
||||||
const { width, height } = coWebsiteManager.getGameSize();
|
const { width, height } = coWebsiteManager.getGameSize();
|
||||||
|
|
||||||
const valueGameQuality = localUserStore.getGameQualityValue();
|
const valueGameQuality = localUserStore.getGameQualityValue();
|
||||||
const fps: Phaser.Types.Core.FPSConfig = {
|
const fps: Phaser.Types.Core.FPSConfig = {
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|||||||
import sveltePreprocess from "svelte-preprocess";
|
import sveltePreprocess from "svelte-preprocess";
|
||||||
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
||||||
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
|
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
|
||||||
import { PROFILE_URL } from "./src/Enum/EnvironmentVariable";
|
import {POSTHOG_API_KEY, PROFILE_URL} from "./src/Enum/EnvironmentVariable";
|
||||||
|
|
||||||
const mode = process.env.NODE_ENV ?? "development";
|
const mode = process.env.NODE_ENV ?? "development";
|
||||||
const buildNpmTypingsForApi = !!process.env.BUILD_TYPINGS;
|
const buildNpmTypingsForApi = !!process.env.BUILD_TYPINGS;
|
||||||
@ -204,6 +204,8 @@ module.exports = {
|
|||||||
MAX_USERNAME_LENGTH: 8,
|
MAX_USERNAME_LENGTH: 8,
|
||||||
MAX_PER_GROUP: 4,
|
MAX_PER_GROUP: 4,
|
||||||
DISPLAY_TERMS_OF_USE: false,
|
DISPLAY_TERMS_OF_USE: false,
|
||||||
|
POSTHOG_API_KEY: null,
|
||||||
|
POSTHOG_URL: null,
|
||||||
NODE_ENV: mode,
|
NODE_ENV: mode,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -83,6 +83,11 @@
|
|||||||
"@nodelib/fs.scandir" "2.1.4"
|
"@nodelib/fs.scandir" "2.1.4"
|
||||||
fastq "^1.6.0"
|
fastq "^1.6.0"
|
||||||
|
|
||||||
|
"@sentry/types@^6.11.0":
|
||||||
|
version "6.12.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.12.0.tgz#b7395688a79403c6df8d8bb8d81deb8222519853"
|
||||||
|
integrity sha512-urtgLzE4EDMAYQHYdkgC0Ei9QvLajodK1ntg71bGn0Pm84QUpaqpPDfHRU+i6jLeteyC7kWwa5O5W1m/jrjGXA==
|
||||||
|
|
||||||
"@tsconfig/svelte@^1.0.10":
|
"@tsconfig/svelte@^1.0.10":
|
||||||
version "1.0.10"
|
version "1.0.10"
|
||||||
resolved "https://registry.yarnpkg.com/@tsconfig/svelte/-/svelte-1.0.10.tgz#30ec7feeee0bdf38b12a50f0686f8a2e7b6b9dc0"
|
resolved "https://registry.yarnpkg.com/@tsconfig/svelte/-/svelte-1.0.10.tgz#30ec7feeee0bdf38b12a50f0686f8a2e7b6b9dc0"
|
||||||
@ -2296,6 +2301,11 @@ faye-websocket@^0.11.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
websocket-driver ">=0.5.1"
|
websocket-driver ">=0.5.1"
|
||||||
|
|
||||||
|
fflate@^0.4.1:
|
||||||
|
version "0.4.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.4.8.tgz#f90b82aefbd8ac174213abb338bd7ef848f0f5ae"
|
||||||
|
integrity sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==
|
||||||
|
|
||||||
file-entry-cache@^6.0.1:
|
file-entry-cache@^6.0.1:
|
||||||
version "6.0.1"
|
version "6.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
|
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
|
||||||
@ -4394,6 +4404,15 @@ postcss@^8.2.10:
|
|||||||
nanoid "^3.1.23"
|
nanoid "^3.1.23"
|
||||||
source-map "^0.6.1"
|
source-map "^0.6.1"
|
||||||
|
|
||||||
|
posthog-js@^1.13.12:
|
||||||
|
version "1.13.12"
|
||||||
|
resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.13.12.tgz#b54efcb92de43724c889048135ccaae3dc4b874c"
|
||||||
|
integrity sha512-MU1I0zSVhdCcnWI8jAZLtbNJmjfg9AnhUDq5dUzNkb0qPXtNz17BekalnNwDMKs0Zlek3UCOVsIpyc85M+VRNA==
|
||||||
|
dependencies:
|
||||||
|
"@sentry/types" "^6.11.0"
|
||||||
|
fflate "^0.4.1"
|
||||||
|
rrweb-snapshot "^1.1.7"
|
||||||
|
|
||||||
prelude-ls@^1.2.1:
|
prelude-ls@^1.2.1:
|
||||||
version "1.2.1"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
|
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
|
||||||
@ -4785,6 +4804,11 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
|
|||||||
hash-base "^3.0.0"
|
hash-base "^3.0.0"
|
||||||
inherits "^2.0.1"
|
inherits "^2.0.1"
|
||||||
|
|
||||||
|
rrweb-snapshot@^1.1.7:
|
||||||
|
version "1.1.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/rrweb-snapshot/-/rrweb-snapshot-1.1.8.tgz#57c3a8003a6ebbe4a2e2f5be29e30a47a8b1eb03"
|
||||||
|
integrity sha512-wi8T9IVobEwlns7U2m8cbPfoihsNAMpTI+UBe4KUjclU2N+vtowD2U1Rq8PleiFTDvcseHvkQDmEIZoZLXFzwg==
|
||||||
|
|
||||||
run-parallel@^1.1.9:
|
run-parallel@^1.1.9:
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
|
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
|
||||||
|
Loading…
Reference in New Issue
Block a user