Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics fixes #472

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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