Skip to content

Commit 9583b2a

Browse files
feat(suite): unify onboarding analytics
1 parent f88405d commit 9583b2a

File tree

8 files changed

+16
-544
lines changed

8 files changed

+16
-544
lines changed

Diff for: packages/analytics/src/utils.ts

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ interface ReportEventProps {
8080
}
8181

8282
export const reportEvent = async ({ type, url, options, retry }: ReportEventProps) => {
83-
console.log({ type, url, options, retry });
84-
8583
try {
8684
const response = await fetch(url, options);
8785

Diff for: packages/suite-analytics/src/constants.ts

-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,4 @@ export enum EventType {
8787
GetDesktopApp = 'promo/desktop',
8888
GetMobileApp = 'promo/mobile',
8989
T2B1DashboardPromo = 'promo/t2b1-dashboard',
90-
91-
OnboardingSelectBackupType = 'onboarding/select-backup-type',
9290
}

Diff for: packages/suite-analytics/src/types/definitions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type OnboardingAnalytics = {
55
firmware: 'install' | 'update' | 'skip' | 'up-to-date';
66
seed: 'create' | 'recovery' | 'recovery-in-progress';
77
seedType: 'shamir-single' | 'shamir-advanced' | '12-words' | '24-words';
8+
wasSelectTypeOpened: boolean;
89
recoveryType: 'standard' | 'advanced';
910
backup: 'create' | 'skip';
1011
pin: 'create' | 'skip';

Diff for: packages/suite-analytics/src/types/events.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export type SuiteAnalyticsEvent =
8787
payload: Partial<Omit<OnboardingAnalytics, 'startTime'>> & {
8888
duration: number;
8989
device: string;
90+
unitPackaging: number;
9091
};
9192
}
9293
| {
@@ -417,13 +418,4 @@ export type SuiteAnalyticsEvent =
417418
payload: {
418419
action: 'shop' | 'close';
419420
};
420-
}
421-
| {
422-
type: EventType.OnboardingSelectBackupType;
423-
payload: {
424-
finalSelectedOption: 'shamir-default' | 'shamir-advance' | '12-words' | '24-words';
425-
wasSelectTypeOpened: boolean;
426-
device: string;
427-
unitPackaging: number;
428-
};
429421
};

Diff for: packages/suite/src/views/onboarding/steps/Final.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export const FinalStep = () => {
221221
...onboardingAnalytics,
222222
duration: Date.now() - onboardingAnalytics.startTime!,
223223
device: device.features.internal_model,
224+
unitPackaging: device.features.unit_packaging ?? 0,
224225
};
225226
delete payload.startTime;
226227

Diff for: packages/suite/src/views/onboarding/steps/ResetDevice.tsx

+4-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from './SelectBackupType/SelectBackupType';
1616
import { DeviceModelInternal } from '@trezor/connect';
1717
import { BackupType } from '../../../reducers/onboarding/onboardingReducer';
18-
import { analytics, EventType } from '@trezor/suite-analytics';
1918

2019
const SelectWrapper = styled.div`
2120
width: 100%;
@@ -49,7 +48,6 @@ export const ResetDeviceStep = () => {
4948

5049
const [submitted, setSubmitted] = useState(false);
5150
const [backupType, setBackupType] = useState<BackupType>(deviceDefaultBackupType);
52-
const [wasSelectTypeOpened, setWasSelectTypeOpened] = useState<boolean>(false);
5351
const { goToPreviousStep, goToNextStep, updateAnalytics, updateBackupType } = useOnboarding();
5452

5553
const dispatch = useDispatch();
@@ -78,16 +76,6 @@ export const ResetDeviceStep = () => {
7876

7977
const handleSubmit = useCallback(
8078
async (type: BackupType) => {
81-
analytics.report({
82-
type: EventType.OnboardingSelectBackupType,
83-
payload: {
84-
wasSelectTypeOpened,
85-
finalSelectedOption: type,
86-
device: deviceModel ?? '',
87-
unitPackaging,
88-
},
89-
});
90-
9179
switch (type) {
9280
case 'shamir-single':
9381
await onResetDevice({ backup_type: 1 });
@@ -104,16 +92,9 @@ export const ResetDeviceStep = () => {
10492
}
10593

10694
updateBackupType(type);
107-
updateAnalytics({ recoveryType: undefined, seedType: type });
95+
updateAnalytics({ seedType: type });
10896
},
109-
[
110-
wasSelectTypeOpened,
111-
deviceModel,
112-
unitPackaging,
113-
updateBackupType,
114-
updateAnalytics,
115-
onResetDevice,
116-
],
97+
[updateBackupType, updateAnalytics, onResetDevice],
11798
);
11899

119100
useEffect(() => {
@@ -173,8 +154,8 @@ export const ResetDeviceStep = () => {
173154
<>
174155
<SelectBackupType
175156
selected={backupType}
176-
onOpen={() => setWasSelectTypeOpened(true)}
177-
onSelect={value => setBackupType(value)}
157+
onOpen={() => updateAnalytics({ wasSelectTypeOpened: true })}
158+
onSelect={setBackupType}
178159
isDisabled={isDeviceLocked}
179160
data-test="@onboarding/select-seed-type-open-dialog"
180161
/>

0 commit comments

Comments
 (0)