Skip to content

Commit

Permalink
feat(suite): unify onboarding analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed May 20, 2024
1 parent d209a0c commit 3be70a3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 32 deletions.
2 changes: 0 additions & 2 deletions packages/suite-analytics/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,4 @@ export enum EventType {
GetDesktopApp = 'promo/desktop',
GetMobileApp = 'promo/mobile',
T2B1DashboardPromo = 'promo/t2b1-dashboard',

OnboardingSelectBackupType = 'onboarding/select-backup-type',
}
1 change: 1 addition & 0 deletions packages/suite-analytics/src/types/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type OnboardingAnalytics = {
firmware: 'install' | 'update' | 'skip' | 'up-to-date';
seed: 'create' | 'recovery' | 'recovery-in-progress';
seedType: 'shamir-default' | 'shamir-advance' | '12-words' | '24-words';
wasSelectTypeOpened: boolean;
recoveryType: 'standard' | 'advanced';
backup: 'create' | 'skip';
pin: 'create' | 'skip';
Expand Down
10 changes: 1 addition & 9 deletions packages/suite-analytics/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type SuiteAnalyticsEvent =
payload: Partial<Omit<OnboardingAnalytics, 'startTime'>> & {
duration: number;
device: string;
unitPackaging: number;
};
}
| {
Expand Down Expand Up @@ -417,13 +418,4 @@ export type SuiteAnalyticsEvent =
payload: {
action: 'shop' | 'close';
};
}
| {
type: EventType.OnboardingSelectBackupType;
payload: {
finalSelectedOption: 'shamir-default' | 'shamir-advance' | '12-words' | '24-words';
wasSelectTypeOpened: boolean;
device: string;
unitPackaging: number;
};
};
1 change: 1 addition & 0 deletions packages/suite/src/views/onboarding/steps/Final.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const FinalStep = () => {
...onboardingAnalytics,
duration: Date.now() - onboardingAnalytics.startTime!,
device: device.features.internal_model,
unitPackaging: device.features.unit_packaging ?? 0,
};
delete payload.startTime;

Expand Down
24 changes: 3 additions & 21 deletions packages/suite/src/views/onboarding/steps/ResetDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Button, Divider, Text } from '@trezor/components';
import { SelectBackupType, getDefaultBackupType, isShamirBackupType } from './SelectBackupType';
import { DeviceModelInternal } from '@trezor/connect';
import { BackupType } from '../../../reducers/onboarding/onboardingReducer';
import { analytics, EventType } from '@trezor/suite-analytics';

const SelectWrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -74,16 +73,6 @@ export const ResetDeviceStep = () => {

const handleSubmit = useCallback(
async (type: BackupType) => {
analytics.report({
type: EventType.OnboardingSelectBackupType,
payload: {
wasSelectTypeOpened,
finalSelectedOption: type,
device: deviceModel ?? '',
unitPackaging,
},
});

switch (type) {
case 'shamir-default':
await onResetDevice({ backup_type: 1 });
Expand All @@ -100,16 +89,9 @@ export const ResetDeviceStep = () => {
}

updateBackupType(type);
updateAnalytics({ recoveryType: undefined, seedType: type });
updateAnalytics({ wasSelectTypeOpened, seedType: type });
},
[
wasSelectTypeOpened,
deviceModel,
unitPackaging,
updateBackupType,
updateAnalytics,
onResetDevice,
],
[wasSelectTypeOpened, updateBackupType, updateAnalytics, onResetDevice],
);

useEffect(() => {
Expand Down Expand Up @@ -170,7 +152,7 @@ export const ResetDeviceStep = () => {
<SelectBackupType
selected={backupType}
onOpen={() => setWasSelectTypeOpened(true)}
onSelect={value => setBackupType(value)}
onSelect={setBackupType}
isDisabled={isDeviceLocked}
data-test="@onboarding/select-seed-type-open-dialog"
/>
Expand Down

0 comments on commit 3be70a3

Please sign in to comment.