Skip to content

Commit

Permalink
Add game and extension version to analytics (#14890)
Browse files Browse the repository at this point in the history
* add game and extension version to user properties

* remove debug mode
  • Loading branch information
insomnious authored Nov 13, 2023
1 parent 41333bc commit 6b9eccb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/extensions/analytics/analytics/AnalyticsGA4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ua from 'universal-analytics';

import { GA4_BETA_MEASUREMENT_ID, GA4_NEXT_MEASUREMENT_ID, GA4_STABLE_MEASUREMENT_ID } from '../constants';
import ga4mp from '../ga4mp/ga4mp.esm';
import { activeGameId } from '../../../util/selectors';

class AnalyticsGA4 {
public user: string;
Expand Down Expand Up @@ -132,13 +133,15 @@ class AnalyticsGA4 {
* @param value
* @returns
*/
public trackEvent(action: string, category?: string, label?: string, value?: string | number | boolean) {
public trackEvent(action: string, category?: string, label?: any, value?: any) {

if (!this.isUserSet()) return;

// if we are activating a game, take the game and update user properties?
if(action === "activate") {
this.ga4track.setUserProperty("Game", label);
this.ga4track.setUserProperty("Game", value.gameId);
this.ga4track.setUserProperty("GameVersion", value.gameVersion);
this.ga4track.setUserProperty("GameExtensionVersion", value.extensionId);
}

// send empty page_view as we don't need it for these events and if we dont, it'll always send a default 'Vortex'
Expand All @@ -151,7 +154,7 @@ class AnalyticsGA4 {
});
}

public setUserProperty(key:string, value: string | number | boolean) {
public setUserProperty(key:string, value: any) {
// this is updated remotely the next time an event is sent
this.ga4track.setUserProperty(key, value);
}
Expand Down
8 changes: 6 additions & 2 deletions src/extensions/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ function init(context: IExtensionContext): boolean {

const gameId = activeGameId(state);
let gameVersion = '';
let extensionVersion = '';
if (gameId) {
gameVersion = await getGame(gameId)
.getInstalledVersion(discoveryByGame(state, gameId));
const game = getGame(gameId);
extensionVersion = game.version;
gameVersion = await game.getInstalledVersion(discoveryByGame(state, gameId));
}

const theme = state.settings.interface['currentTheme'];
Expand Down Expand Up @@ -185,6 +187,8 @@ function init(context: IExtensionContext): boolean {
["VortexVersion"]: getApplication().version,
["Membership"]: membership,
["Game"]: gameId,
["GameVersion"]: gameVersion,
["GameExtensionVersion"]: extensionVersion,
["Theme"]: theme,
["Sandbox"]: state.settings.mods['installerSandbox'] ?? true,
["ModCount"]: modCount,
Expand Down
14 changes: 11 additions & 3 deletions src/extensions/profile_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,17 @@ function init(context: IExtensionContext): boolean {
}, 'Activate', (instanceIds: string[]) => {
const gameId = instanceIds[0];

context.api.events.emit(
'analytics-track-event', 'Games', 'Activate' , gameId,
);
let gameVersion = '';
let extensionVersion = '';
if (gameId) {
const game = getGame(gameId);
extensionVersion = game.version;
game.getInstalledVersion(discoveryByGame(context.api.getState(), gameId)).then((value) => {
gameVersion = value;
});
}

context.api.events.emit( 'analytics-track-event', 'Games', 'Activate' , gameId, {gameId: gameId, gameVersion: gameVersion, extensionVersion: extensionVersion});

checkOverridden(context.api, gameId)
.then(() => {
Expand Down

0 comments on commit 6b9eccb

Please sign in to comment.