Skip to content

Commit

Permalink
Track app open count and stats
Browse files Browse the repository at this point in the history
  • Loading branch information
wyne committed Jul 17, 2024
1 parent 4677f70 commit 18054e0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions redux/SettingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface SettingsState {
interactionType: InteractionType;
lastStoreReviewPrompt: number;
devMenuEnabled?: boolean;
appOpens: number;
};

const initialState: SettingsState = {
Expand All @@ -32,6 +33,7 @@ const initialState: SettingsState = {
showColorPalettes: false,
interactionType: InteractionType.SwipeVertical,
lastStoreReviewPrompt: 0,
appOpens: 0,
};

const settingsSlice = createSlice({
Expand Down Expand Up @@ -76,6 +78,9 @@ const settingsSlice = createSlice({
},
toggleDevMenuEnabled(state) {
state.devMenuEnabled = !state.devMenuEnabled;
},
increaseAppOpens(state) {
state.appOpens += 1;
}
}
});
Expand All @@ -93,6 +98,7 @@ export const {
setInteractionType,
setLastStoreReviewPrompt,
toggleDevMenuEnabled,
increaseAppOpens,
} = settingsSlice.actions;

export default settingsSlice.reducer;
2 changes: 2 additions & 0 deletions redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const settingsPersistConfig = {
'showColorPalettes',
'interactionType',
'lastStoreReviewPrompt',
'devMenuEnabled',
'appOpens',
],
};

Expand Down
2 changes: 1 addition & 1 deletion src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const isDebugMode = process.env.APP_VARIANT == 'development';
const isDebugMode = __DEV__;

const logger = {
log: (...args: unknown[]) => {
Expand Down
20 changes: 19 additions & 1 deletion src/screens/ListScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { memo, useEffect } from 'react';

import analytics from '@react-native-firebase/analytics';
import { ParamListBase } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import * as Application from 'expo-application';
Expand All @@ -11,7 +12,7 @@ import { SemVer, parse } from 'semver';

import { selectGameIds } from '../../redux/GamesSlice';
import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { setOnboardedVersion } from '../../redux/SettingsSlice';
import { increaseAppOpens, setOnboardedVersion } from '../../redux/SettingsSlice';
import GameListItem from '../components/GameListItem';
import { getPendingOnboardingSemVer } from '../components/Onboarding/Onboarding';
import logger from '../Logger';
Expand All @@ -21,6 +22,8 @@ interface Props {
}

const ListScreen: React.FunctionComponent<Props> = ({ navigation }) => {
const appOpens = useAppSelector(state => state.settings.appOpens);
const devMenuEnabled = useAppSelector(state => state.settings.devMenuEnabled);
const gameIds = useAppSelector(state => selectGameIds(state));
const dispatch = useAppDispatch();

Expand All @@ -29,6 +32,7 @@ const ListScreen: React.FunctionComponent<Props> = ({ navigation }) => {
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);
Expand All @@ -37,6 +41,20 @@ const ListScreen: React.FunctionComponent<Props> = ({ navigation }) => {
logger.info(`Pending onboard: ${pendingOnboardingVer}`);
logger.info(`Onboarded: ${onboarded}`);

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

logger.info('App Opens: ', appOpens);
dispatch(increaseAppOpens());
}, []);

useEffect(() => {
if (!onboarded) {
logger.info('Show onboarding!');
Expand Down

0 comments on commit 18054e0

Please sign in to comment.