Skip to content

Commit

Permalink
AppOpen game_list event
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Jul 18, 2024
1 parent 18054e0 commit 21990ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
8 changes: 7 additions & 1 deletion redux/SettingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface SettingsState {
lastStoreReviewPrompt: number;
devMenuEnabled?: boolean;
appOpens: number;
installId: string | undefined;
};

const initialState: SettingsState = {
Expand All @@ -34,6 +35,7 @@ const initialState: SettingsState = {
interactionType: InteractionType.SwipeVertical,
lastStoreReviewPrompt: 0,
appOpens: 0,
installId: undefined,
};

const settingsSlice = createSlice({
Expand Down Expand Up @@ -81,7 +83,10 @@ const settingsSlice = createSlice({
},
increaseAppOpens(state) {
state.appOpens += 1;
}
},
setInstallId(state, action: PayloadAction<string>) {
state.installId = action.payload;
},
}
});

Expand All @@ -99,6 +104,7 @@ export const {
setLastStoreReviewPrompt,
toggleDevMenuEnabled,
increaseAppOpens,
setInstallId,
} = settingsSlice.actions;

export default settingsSlice.reducer;
1 change: 1 addition & 0 deletions redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const settingsPersistConfig = {
'lastStoreReviewPrompt',
'devMenuEnabled',
'appOpens',
'installId',
],
};

Expand Down
28 changes: 18 additions & 10 deletions src/screens/ListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { ParamListBase } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import * as Application from 'expo-application';
import { BlurView } from 'expo-blur';
import * as Crypto from 'expo-crypto';
import { StyleSheet, Text, View } from 'react-native';
import Animated, { Easing, LinearTransition } from 'react-native-reanimated';
import { SafeAreaView } from 'react-native-safe-area-context';
import { SemVer, parse } from 'semver';
import { parse, SemVer } from 'semver';

import { selectGameIds } from '../../redux/GamesSlice';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { increaseAppOpens, setOnboardedVersion } from '../../redux/SettingsSlice';
import { increaseAppOpens, setInstallId, setOnboardedVersion } from '../../redux/SettingsSlice';
import GameListItem from '../components/GameListItem';
import { getPendingOnboardingSemVer } from '../components/Onboarding/Onboarding';
import logger from '../Logger';
Expand All @@ -24,31 +25,38 @@ interface Props {
const ListScreen: React.FunctionComponent<Props> = ({ navigation }) => {
const appOpens = useAppSelector(state => state.settings.appOpens);
const devMenuEnabled = useAppSelector(state => state.settings.devMenuEnabled);
const installId = useAppSelector(state => state.settings.installId);
const gameIds = useAppSelector(state => selectGameIds(state));
const dispatch = useAppDispatch();

const onboardedStr = useAppSelector(state => state.settings.onboarded);
const onboardedSemVer = parse(onboardedStr);
const appVersion = new SemVer(Application.nativeApplicationVersion || '0.0.0');

logger.info(`App Version: ${appVersion}`);
logger.info(`Dev Menu Enabled: ${devMenuEnabled}`);
logger.info(`Onboarded Version: ${onboardedSemVer}`);

const pendingOnboardingVer = getPendingOnboardingSemVer(onboardedSemVer);
const onboarded = pendingOnboardingVer === undefined;

logger.info(`Pending onboard: ${pendingOnboardingVer}`);
logger.info(`Onboarded: ${onboarded}`);

useEffect(() => {
logger.info(`App Version: ${appVersion}`);
logger.info(`Install ID: ${installId}`);
logger.info(`Dev Menu Enabled: ${devMenuEnabled}`);
logger.info(`Onboarded Version: ${onboardedSemVer}`);
logger.info(`Pending onboard: ${pendingOnboardingVer}`);
logger.info(`Onboarded: ${onboarded}`);

if (installId === undefined) {
console.log('no install id');
const installId = Crypto.randomUUID();
dispatch(setInstallId(installId));
}

analytics().logEvent('game_list', {
gameCount: gameIds.length,
appOpens: appOpens,
appVersion: appVersion.version,
devMenuEnabled: devMenuEnabled,
onboardedVersion: onboardedSemVer?.version,
pendingOnboardingVersion: pendingOnboardingVer,
installId: installId,
});

logger.info('App Opens: ', appOpens);
Expand Down

0 comments on commit 21990ac

Please sign in to comment.