Skip to content

Commit 952ed12

Browse files
authored
feat: add additional analytics capture events (#967)
1 parent a6f7583 commit 952ed12

File tree

10 files changed

+107
-39
lines changed

10 files changed

+107
-39
lines changed

src/features/analytics/events.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ export enum Events {
105105
MigrationDownloadLaceClicked = 'nami tool | nami | download lace | click',
106106
MigrationOpenLaceClicked = 'nami tool | nami | open lace | click',
107107
NamiMigrationDismissed = 'nami tool | nami | migration dismissed | click',
108+
109+
// Enhanced migration events
110+
MigrationViewed = 'nami tool | nami | migration tool viewed',
111+
MigrationViewNoWalletViewed = 'nami tool | nami | migration tool | no wallet viewed',
112+
MigrationNoStartedViewed = 'nami tool | nami | migration tool | not started viewed',
113+
MigrationInProgressViewed = 'nami tool | nami | migration tool | in progress viewed',
114+
NamiMigrationDismissedNoWallet = 'nami tool | nami | migration dismissed | no wallet | click',
115+
NamiMigrationDismissedNotStarted = 'nami tool | nami | migration dismissed | not started | click',
116+
NamiMigrationDismissedInProgress = 'nami tool | nami | migration dismissed | in progress | click',
117+
NamiMigrationOpenLaceOrOpenChromeStore = 'nami tool | nami | open lace or open chrome store link | click',
108118
}
109119

110120
export type Property =

src/ui/lace-migration/components/almost-there/almost-there.component.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { ReactComponent as Download } from '../../assets/download.svg';
55
import { ReactComponent as Arrow } from '../../assets/arrow.svg';
66
import { ReactComponent as PendingDark } from '../../assets/pending-dark-mode.svg';
77
import { ReactComponent as PendingWhite } from '../../assets/pending-white-mode.svg';
8+
import { useCaptureEvent } from '../../../../features/analytics/hooks';
9+
import { Events } from '../../../../features/analytics/events';
810

911
export const AlmostThere = ({
1012
isLaceInstalled,
@@ -13,6 +15,7 @@ export const AlmostThere = ({
1315
dismissibleSeconds,
1416
}) => {
1517
const { colorMode } = useColorMode();
18+
const captureEvent = useCaptureEvent();
1619
return (
1720
<Slide
1821
showTerms={false}
@@ -35,10 +38,14 @@ export const AlmostThere = ({
3538
}
3639
buttonText={isLaceInstalled ? 'Open Lace' : 'Download Lace'}
3740
buttonIcon={isLaceInstalled ? Arrow : Download}
38-
onButtonClick={onAction}
41+
onButtonClick={async () => {
42+
await captureEvent(Events.NamiMigrationOpenLaceOrOpenChromeStore);
43+
onAction();
44+
}}
3945
isDismissable={isDismissable}
4046
buttonOrientation="column"
4147
dismissibleSeconds={dismissibleSeconds}
48+
onDismiss={() => captureEvent(Events.NamiMigrationDismissedInProgress)}
4249
/>
4350
);
4451
};

src/ui/lace-migration/components/carousel/slides/Slide1.component.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { Box } from '@chakra-ui/react';
33
import { Slide } from '../../slide.component';
44
import { ReactComponent as Arrow } from '../../../assets/arrow.svg';
55
import { ReactComponent as BackpackImg } from '../../../assets/backpack.svg';
6+
import { useCaptureEvent } from '../../../../../features/analytics/hooks';
7+
import { Events } from '../../../../../features/analytics/events';
68

79
export const Slide1 = ({ onAction, isDismissable, dismissibleSeconds }) => {
10+
const captureEvent = useCaptureEvent();
811
return (
912
<Slide
1013
showTerms
@@ -17,10 +20,13 @@ export const Slide1 = ({ onAction, isDismissable, dismissibleSeconds }) => {
1720
description="The Nami Wallet is now integrated into Lace. Click 'Upgrade your wallet' to begin the process."
1821
buttonText="Upgrade your wallet"
1922
buttonIcon={Arrow}
20-
onButtonClick={onAction}
23+
onButtonClick={async () => await onAction()}
2124
isDismissable={isDismissable}
2225
dismissibleSeconds={dismissibleSeconds}
2326
buttonOrientation={isDismissable ? 'column' : 'row'}
27+
onDismiss={async () =>
28+
captureEvent(Events.NamiMigrationDismissedNotStarted)
29+
}
2430
/>
2531
);
2632
};

src/ui/lace-migration/components/carousel/slides/Slide2.component.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { ReactComponent as Arrow } from '../../../assets/arrow.svg';
44
import { ReactComponent as SeamlessDark } from '../../../assets/grouped-dark-mode.svg';
55
import { ReactComponent as SeamlessWhite } from '../../../assets/grouped-white-mode.svg';
66
import { useColorMode, Box } from '@chakra-ui/react';
7+
import { useCaptureEvent } from '../../../../../features/analytics/hooks';
8+
import { Events } from '../../../../../features/analytics/events';
79

810
export const Slide2 = ({ onAction, isDismissable, dismissibleSeconds }) => {
911
const { colorMode } = useColorMode();
12+
const captureEvent = useCaptureEvent();
1013
return (
1114
<Slide
1215
showTerms
@@ -27,6 +30,9 @@ export const Slide2 = ({ onAction, isDismissable, dismissibleSeconds }) => {
2730
isDismissable={isDismissable}
2831
dismissibleSeconds={dismissibleSeconds}
2932
buttonOrientation={isDismissable ? 'column' : 'row'}
33+
onDismiss={async () =>
34+
captureEvent(Events.NamiMigrationDismissedNotStarted)
35+
}
3036
/>
3137
);
3238
};

src/ui/lace-migration/components/carousel/slides/Slide3.component.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { Slide } from '../../slide.component';
33
import { ReactComponent as Arrow } from '../../../assets/arrow.svg';
44
import { Box } from '@chakra-ui/react';
55
import { ReactComponent as FeaturesImg } from '../../../assets/features.svg';
6+
import { useCaptureEvent } from '../../../../../features/analytics/hooks';
7+
import { Events } from '../../../../../features/analytics/events';
68

79
export const Slide3 = ({ onAction, isDismissable, dismissibleSeconds }) => {
10+
const captureEvent = useCaptureEvent();
811
return (
912
<Slide
1013
showTerms
@@ -21,6 +24,9 @@ export const Slide3 = ({ onAction, isDismissable, dismissibleSeconds }) => {
2124
isDismissable={isDismissable}
2225
dismissibleSeconds={dismissibleSeconds}
2326
buttonOrientation={isDismissable ? 'column' : 'row'}
27+
onDismiss={async () =>
28+
captureEvent(Events.NamiMigrationDismissedNotStarted)
29+
}
2430
/>
2531
);
2632
};

src/ui/lace-migration/components/dismiss-btn.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { Text } from './text.component';
44
import { dismissMigration } from '../../../api/migration-tool/cross-extension-messaging/nami-migration-client.extension';
55
import { ReactComponent as PendingDark } from '../assets/clock.svg';
66

7-
export const DismissBtn = ({ dismissableIntervalSeconds, hasIcon }) => {
7+
export const DismissBtn = ({
8+
dismissableIntervalSeconds,
9+
hasIcon,
10+
onDismiss,
11+
}) => {
812
const futureDate = new Date();
913
const futureTime = futureDate.setTime(
1014
futureDate.getTime() + dismissableIntervalSeconds * 1000
@@ -22,6 +26,7 @@ export const DismissBtn = ({ dismissableIntervalSeconds, hasIcon }) => {
2226
border="2px solid transparent"
2327
backgroundColor="none"
2428
onClick={async () => {
29+
onDismiss();
2530
await dismissMigration({ dismissMigrationUntil: futureTime });
2631
}}
2732
>

src/ui/lace-migration/components/migration-view/migration-view.component.jsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { MigrationState } from '../../../../api/migration-tool/migrator/migration-state.data';
33
import { Carousel } from '../carousel/carousel.component';
44
import { Slide1 } from '../carousel/slides/Slide1.component';
@@ -9,6 +9,10 @@ import { AllDone } from '../all-done/all-done.component';
99
import { NoWallet } from '../no-wallet/no-wallet.component';
1010
import { useColorModeValue, Flex } from '@chakra-ui/react';
1111
import { useFeatureFlagsContext } from '../../../../features/feature-flags/provider';
12+
import { Events } from '../../../../features/analytics/events';
13+
import { useCaptureEvent } from '../../../../features/analytics/hooks';
14+
import { AnalyticsConsentModal } from '../../../../features/analytics/ui/AnalyticsConsentModal';
15+
import { useAnalyticsContext } from '../../../../features/analytics/provider';
1216

1317
export const MigrationView = ({
1418
migrationState,
@@ -26,15 +30,22 @@ export const MigrationView = ({
2630
const panelBg = useColorModeValue('#349EA3', 'gray.800');
2731
const bgColor = useColorModeValue('#FFF', '#1A202C');
2832
const { featureFlags } = useFeatureFlagsContext();
33+
const [analytics, setAnalyticsConsent] = useAnalyticsContext();
34+
const captureEvent = useCaptureEvent();
35+
useEffect(() => {
36+
captureEvent(Events.MigrationViewed);
37+
}, []);
38+
2939
const isDismissable =
3040
featureFlags?.['is-migration-active']?.dismissable || false;
3141

3242
const dismissibleSeconds =
3343
featureFlags?.['is-migration-active']?.dismissInterval;
3444

3545
if (!hasWallet) {
46+
captureEvent(Events.MigrationViewNoWalletViewed);
3647
return (
37-
<Flex
48+
<><Flex
3849
h="100%"
3950
backgroundColor={panelBg}
4051
>
@@ -57,12 +68,18 @@ export const MigrationView = ({
5768
/>
5869
</Flex>
5970
</Flex>
71+
<AnalyticsConsentModal
72+
askForConsent={analytics.consent === undefined}
73+
setConsent={setAnalyticsConsent}
74+
/>
75+
</>
6076
);
6177
}
6278

6379
switch (migrationState) {
6480
case MigrationState.Dismissed:
6581
case MigrationState.None:
82+
captureEvent(Events.MigrationNoStartedViewed);
6683
return (
6784
<Flex
6885
h="100%"

src/ui/lace-migration/components/migration.component.jsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,35 +137,35 @@ export const AppWithMigration = () => {
137137
slideIndex: nextSlideIndex,
138138
});
139139
}}
140-
onUpgradeWalletClicked={() => {
140+
onUpgradeWalletClicked={async() => {
141141
enableMigration();
142-
captureEvent(Events.MigrationUpgradeYourWalletClicked);
142+
await captureEvent(Events.MigrationUpgradeYourWalletClicked);
143143
}}
144-
onWaitingForLaceScreenViewed={() => {
145-
captureEvent(Events.MigrationDownloadLaceScreenViewed);
144+
onWaitingForLaceScreenViewed={async() => {
145+
await captureEvent(Events.MigrationDownloadLaceScreenViewed);
146146
}}
147-
onOpenLaceScreenViewed={() => {
148-
captureEvent(Events.MigrationOpenLaceScreenViewed);
147+
onOpenLaceScreenViewed={async() => {
148+
await captureEvent(Events.MigrationOpenLaceScreenViewed);
149149
}}
150-
onDownloadLaceClicked={() => {
151-
captureEvent(Events.MigrationDownloadLaceClicked);
150+
onDownloadLaceClicked={async() => {
151+
await captureEvent(Events.MigrationDownloadLaceClicked);
152152
window.open(
153153
`https://chromewebstore.google.com/detail/lace/${secrets.LACE_EXTENSION_ID}`
154154
);
155155
}}
156-
onOpenLaceClicked={() => {
157-
captureEvent(Events.MigrationOpenLaceClicked);
156+
onOpenLaceClicked={async() => {
157+
await captureEvent(Events.MigrationOpenLaceClicked);
158158
openLace();
159159
}}
160-
onAllDoneScreenViewed={() => {
161-
captureEvent(Events.MigrationAllDoneScreenViewed);
160+
onAllDoneScreenViewed={async() => {
161+
await captureEvent(Events.MigrationAllDoneScreenViewed);
162162
}}
163-
onNoWalletActionClick={() => {
163+
onNoWalletActionClick={async() => {
164164
if (state.isLaceInstalled) {
165-
captureEvent(Events.MigrationOpenLaceClicked, { noWallet: true });
165+
await captureEvent(Events.MigrationOpenLaceClicked);
166166
openLace();
167167
} else {
168-
captureEvent(Events.MigrationDownloadLaceClicked, { noWallet: true });
168+
await captureEvent(Events.MigrationDownloadLaceClicked);
169169
window.open(
170170
`https://chromewebstore.google.com/detail/lace/${secrets.LACE_EXTENSION_ID}`
171171
);

src/ui/lace-migration/components/no-wallet/no-wallet.component.jsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@ import { Slide } from '../slide.component';
33
import { ReactComponent as LaceIcon } from '../../assets/lace-icon.svg';
44
import { ReactComponent as BackpackImg } from '../../assets/backpack.svg';
55
import { Box } from '@chakra-ui/react';
6+
import { useCaptureEvent } from '../../../../features/analytics/hooks';
7+
import { Events } from '../../../../features/analytics/events';
68

7-
export const NoWallet = ({ onAction, isDismissable, dismissibleSeconds }) => (
8-
<Slide
9-
title="Your Nami wallet has upgraded!"
10-
image={
11-
<Box mb={'38px'}>
12-
<BackpackImg width="91px" height="126px" />
13-
</Box>
14-
}
15-
description="To create or import a wallet, proceed using the Lace extension."
16-
buttonText="Get started with Lace"
17-
buttonIcon={LaceIcon}
18-
onButtonClick={onAction}
19-
isDismissable={isDismissable}
20-
buttonOrientation={isDismissable ? 'column' : 'row'}
21-
dismissibleSeconds={dismissibleSeconds}
22-
showTerms={false}
23-
showFindOutMore
24-
/>
25-
);
9+
export const NoWallet = ({ onAction, isDismissable, dismissibleSeconds }) => {
10+
const captureEvent = useCaptureEvent();
11+
12+
return (
13+
<Slide
14+
title="Your Nami wallet has upgraded!"
15+
image={
16+
<Box mb={'38px'}>
17+
<BackpackImg width="91px" height="126px" />
18+
</Box>
19+
}
20+
description="To create or import a wallet, proceed using the Lace extension."
21+
buttonText="Get started with Lace"
22+
buttonIcon={LaceIcon}
23+
onButtonClick={onAction}
24+
isDismissable={isDismissable}
25+
buttonOrientation={isDismissable ? 'column' : 'row'}
26+
dismissibleSeconds={dismissibleSeconds}
27+
showTerms={false}
28+
showFindOutMore
29+
onDismiss={async () =>
30+
captureEvent(Events.NamiMigrationDismissedNoWallet)
31+
}
32+
/>
33+
);
34+
};

src/ui/lace-migration/components/slide.component.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const Slide = ({
1616
dismissibleSeconds,
1717
buttonOrientation,
1818
showFindOutMore,
19+
onDismiss,
1920
}) => {
2021
const borderColor = useColorModeValue('#C0C0C0', '#383838');
2122
const slideBoxBgColor = useColorModeValue('#FFFFFF', '#2D3848');
@@ -199,6 +200,7 @@ export const Slide = ({
199200
<DismissBtn
200201
hasIcon={buttonOrientation === 'column'}
201202
dismissableIntervalSeconds={dismissibleSeconds}
203+
onDismiss={onDismiss}
202204
/>
203205
)}
204206
</Flex>

0 commit comments

Comments
 (0)