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 Jun 5, 2024
1 parent f88405d commit 9583b2a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 544 deletions.
2 changes: 0 additions & 2 deletions packages/analytics/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ interface ReportEventProps {
}

export const reportEvent = async ({ type, url, options, retry }: ReportEventProps) => {
console.log({ type, url, options, retry });

try {
const response = await fetch(url, options);

Expand Down
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-single' | 'shamir-advanced' | '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
27 changes: 4 additions & 23 deletions packages/suite/src/views/onboarding/steps/ResetDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from './SelectBackupType/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 @@ -49,7 +48,6 @@ export const ResetDeviceStep = () => {

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

const dispatch = useDispatch();
Expand Down Expand Up @@ -78,16 +76,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-single':
await onResetDevice({ backup_type: 1 });
Expand All @@ -104,16 +92,9 @@ export const ResetDeviceStep = () => {
}

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

useEffect(() => {
Expand Down Expand Up @@ -173,8 +154,8 @@ export const ResetDeviceStep = () => {
<>
<SelectBackupType
selected={backupType}
onOpen={() => setWasSelectTypeOpened(true)}
onSelect={value => setBackupType(value)}
onOpen={() => updateAnalytics({ wasSelectTypeOpened: true })}
onSelect={setBackupType}
isDisabled={isDeviceLocked}
data-test="@onboarding/select-seed-type-open-dialog"
/>
Expand Down
Loading

0 comments on commit 9583b2a

Please sign in to comment.