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

M2-4997 (common task), M2-5076, M2-4991, M2-5257: add some new mixpanel events #607

Merged
merged 5 commits into from
Feb 15, 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: 1 addition & 3 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LogBox } from 'react-native';
import { RootNavigator } from '@screens';

import localization from '@jobs/localization';
import { Logger, jobRunner, AnalyticsService } from '@shared/lib';
import { Logger, jobRunner } from '@shared/lib';

import { AppProvider } from './ui';

Expand All @@ -18,8 +18,6 @@ jobRunner.runAll([localization]);

Logger.configure();

AnalyticsService.init();

const App = () => {
return (
<AppProvider>
Expand Down
19 changes: 19 additions & 0 deletions src/app/ui/AppProvider/AnalyticsProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { FC, PropsWithChildren, useEffect } from 'react';

import { AnalyticsService, Logger, useSystemBootUp } from '@app/shared/lib';

const AnalyticsProvider: FC<PropsWithChildren> = ({ children }) => {
const { onModuleInitialized } = useSystemBootUp();

useEffect(() => {
AnalyticsService.init().then(() => {
Logger.log('[AnalyticsProvider]: Initialized');

onModuleInitialized('analytics');
});
}, [onModuleInitialized]);

return <>{children}</>;
};

export default AnalyticsProvider;
2 changes: 1 addition & 1 deletion src/app/ui/AppProvider/SystemBootUpProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = PropsWithChildren<{
const SYSTEM_BOOT_UP_DELAY = 300;

function SystemBootUpProvider({ children, onLoadingFinished }: Props) {
const moduleWaitList = useRef(['cache', 'state']);
const moduleWaitList = useRef(['cache', 'state', 'analytics']);

const onLoadingFinishedRef = useRef(onLoadingFinished);

Expand Down
48 changes: 30 additions & 18 deletions src/app/ui/AppProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { Dirs } from 'react-native-file-access';
import { GestureHandlerRootView } from 'react-native-gesture-handler';

import { LocalizationProvider } from '@app/entities/localization';
import { AnalyticsService, Logger, MixEvents } from '@app/shared/lib';

import AnalyticsProvider from './AnalyticsProvider';
import NavigationProvider from './NavigationProvider';
import ReactQueryProvider from './ReactQueryProvider';
import ReduxProvider from './ReduxProvider';
Expand All @@ -27,26 +29,36 @@ CacheManager.config = {
const AppProvider: FC<PropsWithChildren> = ({ children }) => {
const [isBootingUp, setIsBootingUp] = useState(true);

const onLoadingFinished = () => {
Logger.log('[AppProvider]: App loaded');

AnalyticsService.track(MixEvents.AppOpen);

setIsBootingUp(false);
};

return (
<GestureHandlerRootView style={styles.gestureHandlerView}>
<SystemBootUpProvider onLoadingFinished={() => setIsBootingUp(false)}>
<ReduxProvider>
<ReactQueryProvider>
<LocalizationProvider>
<TamaguiProvider>
<NavigationProvider>
<PortalProvider>
<ToastProvider>
<SplashProvider isLoading={isBootingUp}>
{children}
</SplashProvider>
</ToastProvider>
</PortalProvider>
</NavigationProvider>
</TamaguiProvider>
</LocalizationProvider>
</ReactQueryProvider>
</ReduxProvider>
<SystemBootUpProvider onLoadingFinished={onLoadingFinished}>
<AnalyticsProvider>
<ReduxProvider>
<ReactQueryProvider>
<LocalizationProvider>
<TamaguiProvider>
<NavigationProvider>
<PortalProvider>
<ToastProvider>
<SplashProvider isLoading={isBootingUp}>
{children}
</SplashProvider>
</ToastProvider>
</PortalProvider>
</NavigationProvider>
</TamaguiProvider>
</LocalizationProvider>
</ReactQueryProvider>
</ReduxProvider>
</AnalyticsProvider>
</SystemBootUpProvider>
</GestureHandlerRootView>
);
Expand Down
4 changes: 2 additions & 2 deletions src/entities/activity/lib/hooks/useRetryUpload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { AnalyticsService } from '@shared/lib';
import { AnalyticsService, MixEvents } from '@shared/lib';

import { showUploadErrorAlert } from '../alerts';
import { UploadObservable } from '../observables';
Expand Down Expand Up @@ -28,7 +28,7 @@ export const useRetryUpload = ({

showUploadErrorAlert({
onRetry: async () => {
AnalyticsService.track('Retry button pressed');
AnalyticsService.track(MixEvents.RetryButtonPressed);
try {
setIsAlertOpened(false);

Expand Down
4 changes: 2 additions & 2 deletions src/entities/activity/ui/UploadRetryBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AccessibilityProps } from 'react-native';
import { useTranslation } from 'react-i18next';

import { Box, Button, Text } from '@app/shared/ui';
import { AnalyticsService } from '@shared/lib';
import { AnalyticsService, MixEvents } from '@shared/lib';

import useQueueProcessing from '../lib/hooks/useQueueProcessing';

Expand All @@ -16,7 +16,7 @@ const UploadRetryBanner: FC<Props> = () => {
const { t } = useTranslation();

const onRetry = () => {
AnalyticsService.track('Retry button pressed');
AnalyticsService.track(MixEvents.RetryButtonPressed);
process();
};

Expand Down
99 changes: 68 additions & 31 deletions src/entities/applet/model/hooks/useStartEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
ILogger,
isAppOnline,
Logger,
MixEvents,
MixProperties,
useAppDispatch,
useAppletInfo,
useAppSelector,
Expand Down Expand Up @@ -125,6 +127,36 @@ function useStartEntity({
});
};

const appletName = getAppletDisplayName(appletId);

const logStart = () => {
logger.log(
`[useStartEntity.startActivity]: Activity "${entityName}|${activityId}" started, applet "${appletName}|${appletId}"`,
);
AnalyticsService.track(MixEvents.AssessmentStarted, {
[MixProperties.AppletId]: appletId,
});
};
const logRestart = () => {
logger.log(
`[useStartEntity.startActivity]: Activity "${entityName}|${activityId}" restarted, applet "${appletName}|${appletId}"`,
);
AnalyticsService.track(MixEvents.ActivityRestart, {
[MixProperties.AppletId]: appletId,
});
AnalyticsService.track(MixEvents.AssessmentStarted, {
[MixProperties.AppletId]: appletId,
});
};
const logResume = () => {
logger.log(
`[useStartEntity.startActivity]: Activity "${entityName}|${activityId}" resumed, applet "${appletName}|${appletId}"`,
);
AnalyticsService.track(MixEvents.ActivityResume, {
[MixProperties.AppletId]: appletId,
});
};

return new Promise<StartResult>(resolve => {
if (shouldBreakDueToMediaReferences()) {
onMediaReferencesFound();
Expand All @@ -148,8 +180,6 @@ function useStartEntity({
getProgress(appletId, activityId, eventId),
);

const appletName = getAppletDisplayName(appletId);

if (isActivityInProgress) {
if (isTimerElapsed) {
resolve({ startedFromScratch: false });
Expand All @@ -159,27 +189,17 @@ function useStartEntity({
onBeforeStartingActivity({
onRestart: () => {
cleanUpMediaFiles({ activityId, appletId, eventId, order: 0 });

logger.log(
`[useStartEntity.startActivity]: Activity "${entityName}|${activityId}" restarted, applet "${appletName}|${appletId}"`,
);
logRestart();
activityStarted(appletId, activityId, eventId);
resolve({ startedFromScratch: true });
},
onResume: () => {
logger.log(
`[useStartEntity.startActivity]: Activity "${entityName}|${activityId}" resumed, applet "${appletName}|${appletId}"`,
);
logResume();
return resolve({ startedFromScratch: false });
},
});
} else {
logger.log(
`[useStartEntity.startActivity]: Activity "${entityName}|${activityId}" started, applet "${appletName}|${appletId}"`,
);

AnalyticsService.track('Assessment started');

logStart();
activityStarted(appletId, activityId, eventId);
resolve({ startedFromScratch: true });
}
Expand Down Expand Up @@ -230,6 +250,36 @@ function useStartEntity({
return flow.activityIds;
};

const appletName = getAppletDisplayName(appletId);

const logStart = () => {
logger.log(
`[useStartEntity.startFlow]: Flow "${entityName}|${flowId}" started, applet "${appletName}|${appletId}"`,
);
AnalyticsService.track(MixEvents.AssessmentStarted, {
[MixProperties.AppletId]: appletId,
});
};
const logRestart = () => {
logger.log(
`[useStartEntity.startFlow]: Flow "${entityName}|${flowId}" restarted, applet "${appletName}|${appletId}"`,
);
AnalyticsService.track(MixEvents.ActivityRestart, {
[MixProperties.AppletId]: appletId,
});
AnalyticsService.track(MixEvents.AssessmentStarted, {
[MixProperties.AppletId]: appletId,
});
};
const logResume = () => {
logger.log(
`[useStartEntity.startFlow]: Flow "${entityName}|${flowId}" resumed, applet "${appletName}|${appletId}"`,
);
AnalyticsService.track(MixEvents.ActivityResume, {
[MixProperties.AppletId]: appletId,
});
};

const flowActivities: string[] = getFlowActivities();

const firstActivityId: string = flowActivities[0];
Expand All @@ -255,8 +305,6 @@ function useStartEntity({
getProgress(appletId, flowId, eventId),
);

const appletName = getAppletDisplayName(appletId);

if (isFlowInProgress) {
if (isTimerElapsed) {
resolve({
Expand All @@ -275,32 +323,21 @@ function useStartEntity({
order: i,
});
}
logger.log(
`[useStartEntity.startFlow]: Flow "${entityName}|${flowId}" restarted, applet "${appletName}|${appletId}"`,
);

logRestart();
flowStarted(appletId, flowId, firstActivityId, eventId, 0);
resolve({
startedFromScratch: true,
});
},
onResume: () => {
logger.log(
`[useStartEntity.startFlow]: Flow "${entityName}|${flowId}" resumed, applet "${appletName}|${appletId}"`,
);

logResume();
return resolve({
startedFromScratch: false,
});
},
});
} else {
logger.log(
`[useStartEntity.startFlow]: Flow "${entityName}|${flowId}" started, applet "${appletName}|${appletId}"`,
);

AnalyticsService.track('Assessment started');

logStart();
flowStarted(appletId, flowId, firstActivityId, eventId, 0);
resolve({
startedFromScratch: true,
Expand Down
3 changes: 2 additions & 1 deletion src/features/login/ui/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SessionModel } from '@entities/session';
import {
AnalyticsService,
executeIfOnline,
MixEvents,
useAppDispatch,
useAppForm,
useFormChanges,
Expand Down Expand Up @@ -61,7 +62,7 @@ const LoginForm: FC<Props> = props => {
SessionModel.storeSession(session);

AnalyticsService.login(user.id).then(() => {
AnalyticsService.track('Login Successful');
AnalyticsService.track(MixEvents.LoginSuccessful);
});

props.onLoginSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const getEmptyRadioItem = (name: string): RadioPipelineItem => {
setAlerts: false,
setPalette: false,
options: [],
autoAdvance: false,
},
type: 'Radio',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const getEmptyItem = (): RadioPipelineItem => {
setAlerts: false,
setPalette: false,
options: [],
autoAdvance: false,
},
type: 'Radio',
};
Expand Down
8 changes: 6 additions & 2 deletions src/features/pass-survey/ui/ActivityStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Props = {
idleTimer: HourMinute | null;
entityStartedAt: number;
timer: HourMinute | null;
onClose: () => void;
onClose: (reason: 'regular' | 'click-on-return') => void;
onFinish: (reason: 'regular' | 'idle') => void;
};

Expand Down Expand Up @@ -207,6 +207,10 @@ function ActivityStepper({
restartIdleTimer();
};

const onStartReached = () => {
onClose('click-on-return');
};

const onEndReached = (isForced: boolean) => {
if (!isForced) {
trackUserAction(userActionCreator.done());
Expand All @@ -233,7 +237,7 @@ function ActivityStepper({
onBack={onBack}
onBeforeNext={onBeforeNext}
onBeforeBack={onBeforeBack}
onStartReached={onClose}
onStartReached={onStartReached}
onEndReached={onEndReached}
onUndo={onUndo}
>
Expand Down
4 changes: 2 additions & 2 deletions src/features/sign-up/model/hooks/useRegistrationMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
IdentityModel,
} from '@entities/identity';
import { SessionModel } from '@entities/session';
import { AnalyticsService, useAppDispatch } from '@shared/lib';
import { AnalyticsService, MixEvents, useAppDispatch } from '@shared/lib';
import { encryption } from '@shared/lib';

type UseRegistrationReturn = {
Expand Down Expand Up @@ -49,7 +49,7 @@ export const useRegistrationMutation = (
SessionModel.storeSession(session);

AnalyticsService.login(user.id).then(() => {
AnalyticsService.track('Signup Successful');
AnalyticsService.track(MixEvents.SignupSuccessful);
});

if (onSuccess) {
Expand Down
Loading