diff --git a/redux/SettingsSlice.ts b/redux/SettingsSlice.ts index db175b2a..8212e2cc 100644 --- a/redux/SettingsSlice.ts +++ b/redux/SettingsSlice.ts @@ -92,6 +92,9 @@ const settingsSlice = createSlice({ incrementRollingGameCounter(state) { state.rollingGameCounter = (state.rollingGameCounter ?? 0) + 1; }, + setRollingGameCounter(state, action: PayloadAction) { + state.rollingGameCounter = action.payload; + }, } }); @@ -111,6 +114,7 @@ export const { increaseAppOpens, setInstallId, incrementRollingGameCounter, + setRollingGameCounter, } = settingsSlice.actions; export default settingsSlice.reducer; diff --git a/src/Analytics.ts b/src/Analytics.ts index 3da97e34..ca44cd0e 100644 --- a/src/Analytics.ts +++ b/src/Analytics.ts @@ -1,4 +1,6 @@ import analytics from '@react-native-firebase/analytics'; +import * as Application from 'expo-application'; +import { Platform } from 'react-native'; import logger from './Logger'; @@ -9,15 +11,29 @@ import logger from './Logger'; */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export const logEvent = async (eventName: string, params?: Record) => { - // Additional logging logic here (e.g., console.log for debugging) + const appInstanceId = await analytics().getAppInstanceId(); + const sessionId = await analytics().getSessionId(); + const os = Platform.OS; + const osVersion = Platform.Version; + const appVersion = Application.nativeApplicationVersion; + + const fullParams = { + ...params, + appInstanceId, + sessionId, + os, + appVersion, + osVersion, + }; + logger.info( '\x1b[34m', // Set the color to blue 'EVENT', eventName, - JSON.stringify(params, null, 2), + JSON.stringify(fullParams, null, 2), '\x1b[0m' // Reset the color ); // Log the event to Firebase Analytics - await analytics().logEvent(eventName, params); + await analytics().logEvent(eventName, fullParams); }; diff --git a/src/screens/ListScreen.tsx b/src/screens/ListScreen.tsx index 5328c432..ae9800f9 100644 --- a/src/screens/ListScreen.tsx +++ b/src/screens/ListScreen.tsx @@ -12,7 +12,7 @@ import { SemVer, parse } from 'semver'; import { selectGameIds } from '../../redux/GamesSlice'; import { useAppDispatch, useAppSelector } from '../../redux/hooks'; -import { increaseAppOpens, setInstallId, setOnboardedVersion } from '../../redux/SettingsSlice'; +import { increaseAppOpens, setInstallId, setOnboardedVersion, setRollingGameCounter } from '../../redux/SettingsSlice'; import { logEvent } from '../Analytics'; import GameListItem from '../components/GameListItem'; import { getPendingOnboardingSemVer } from '../components/Onboarding/Onboarding'; @@ -38,11 +38,16 @@ const ListScreen: React.FunctionComponent = ({ navigation }) => { useEffect(() => { if (installId === undefined) { - logger.log('No install id'); const installId = Crypto.randomUUID(); dispatch(setInstallId(installId)); } + // Update rollingGameCounter if it is undefined or less than the current gameIds length + if (rollingGameCounter === undefined || rollingGameCounter < gameIds.length) { + setRollingGameCounter(gameIds.length); + } + + logEvent('game_list', { onboarded, gameCount: gameIds.length,