Skip to content

Commit

Permalink
Analytics tracking for seedVerifyQuiz (#1751)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
BrodyHughes and DanielSinclair authored Nov 6, 2024
1 parent d2d48cb commit dfa01e4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/analytics/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ export const event = {
* Called when the user toggles Degen Mode in the Swap/Bridge flow.
*/
toggledDegenMode: 'degenMode.toggled',
/**
* Called when user completes or skips the wallet backup flow.
* potential outcomes are 'succeeded,' 'failed,' or 'skipped.'
*/
walletBackupQuizSubmitted: 'wallet.backup_quiz.submitted',
/**
* Called when the core wallet Tokens & Activity
* screen is viewed or opened in the extension popup.
Expand Down Expand Up @@ -847,6 +852,22 @@ export type EventProperties = {
*/
hardwareWallet: boolean;
};
[event.walletBackupQuizSubmitted]: {
/**
* Completed: if the user successfully completes the wallet backup quiz.
* Failed: if the user fails to complete the backup quiz.
* Skipped: if the user opts to skip the backup quiz completely.
*/
status: 'completed' | 'failed' | 'skipped';
/**
* The entry point of the wallet backup quiz.
*/
entryPoint: 'onboarding' | 'settings';
/**
* Index of the wallet seed to track how many backups are completed.
*/
index: number;
};
[event.walletViewed]: undefined;
[event.toggledDegenMode]: { enabled: boolean };
};
35 changes: 33 additions & 2 deletions src/entries/popup/components/SeedVerifyQuiz/SeedVerifyQuiz.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Address } from 'viem';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import { i18n } from '~/core/languages';
import { useWalletBackupsStore } from '~/core/state/walletBackups';
import {
Expand Down Expand Up @@ -138,10 +140,12 @@ export function SeedVerifyQuiz({
address,
onQuizValidated,
handleSkip,
entryPoint,
}: {
address: Address;
onQuizValidated: () => void;
handleSkip: () => void;
entryPoint: 'onboarding' | 'settings';
}) {
const [seed, setSeed] = useState('');
const [validated, setValidated] = useState(false);
Expand All @@ -153,6 +157,8 @@ export function SeedVerifyQuiz({
const [selectedWords, setSelectedWords] = useState<SeedWord[]>([]);

const setWalletBackedUp = useWalletBackupsStore.use.setWalletBackedUp();
const walletBackups = useWalletBackupsStore.use.walletBackups();

const seedBoxBorderColor = useMemo(() => {
if (validated) return globalColors.green90;
if (incorrect) return globalColors.red90;
Expand Down Expand Up @@ -186,17 +192,35 @@ export function SeedVerifyQuiz({
setWalletBackedUp({ address });
onQuizValidated();
}, 1200);
analytics.track(event.walletBackupQuizSubmitted, {
status: 'completed',
entryPoint,
index: Object.keys(walletBackups).indexOf(address),
});
} else {
playSound('IncorrectSeedQuiz');
setIncorrect(true);
analytics.track(event.walletBackupQuizSubmitted, {
status: 'failed',
entryPoint,
index: Object.keys(walletBackups).indexOf(address),
});
}
}, 100);
} else {
setValidated(false);
setIncorrect(false);
}
},
[address, onQuizValidated, seed, selectedWords, setWalletBackedUp],
[
address,
entryPoint,
onQuizValidated,
seed,
selectedWords,
setWalletBackedUp,
walletBackups,
],
);

useEffect(() => {
Expand Down Expand Up @@ -321,7 +345,14 @@ export function SeedVerifyQuiz({
height="44px"
variant="transparent"
width="full"
onClick={handleSkip}
onClick={() => {
handleSkip();
analytics.track(event.walletBackupQuizSubmitted, {
status: 'skipped',
entryPoint,
index: Object.keys(walletBackups).indexOf(address),
});
}}
testId="skip-this-button"
tabIndex={0}
>
Expand Down
1 change: 1 addition & 0 deletions src/entries/popup/pages/seedVerify/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function SeedVerify() {
address={currentAddress}
onQuizValidated={goToCreatePassword}
handleSkip={goToCreatePassword}
entryPoint="onboarding"
/>
</FullScreenContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function RecoveryPhraseVerify() {
ROUTES.SETTINGS__PRIVACY__WALLETS_AND_KEYS__WALLET_DETAILS,
)
}
entryPoint="settings"
/>
</Box>
);
Expand Down

0 comments on commit dfa01e4

Please sign in to comment.