Skip to content

Commit

Permalink
Merge pull request #472 from wyne/analytics-fixes
Browse files Browse the repository at this point in the history
Analytics fixes
  • Loading branch information
wyne authored Jul 24, 2024
2 parents 9c8602c + 7b75a09 commit 943d501
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions redux/SettingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const settingsSlice = createSlice({
incrementRollingGameCounter(state) {
state.rollingGameCounter = (state.rollingGameCounter ?? 0) + 1;
},
setRollingGameCounter(state, action: PayloadAction<number>) {
state.rollingGameCounter = action.payload;
},
}
});

Expand All @@ -111,6 +114,7 @@ export const {
increaseAppOpens,
setInstallId,
incrementRollingGameCounter,
setRollingGameCounter,
} = settingsSlice.actions;

export default settingsSlice.reducer;
22 changes: 19 additions & 3 deletions src/Analytics.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<string, any>) => {
// 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);
};
9 changes: 7 additions & 2 deletions src/screens/ListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -38,11 +38,16 @@ const ListScreen: React.FunctionComponent<Props> = ({ 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,
Expand Down

0 comments on commit 943d501

Please sign in to comment.