Skip to content

Commit a5ed2a7

Browse files
LucasDominikGuzei
andauthored
feat(extension): [LW-8998] Add missing tracking points around dApp connector submission in Lace (#701)
--------- Co-authored-by: Dominik Guzei <dominik.guzei@gmail.com>
1 parent 53dce7f commit a5ed2a7

File tree

11 files changed

+139
-44
lines changed

11 files changed

+139
-44
lines changed

apps/browser-extension-wallet/src/features/dapp/components/ConfirmData.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState, useCallback, useMemo } from 'react';
22
import { Wallet } from '@lace/cardano';
3-
import { Button } from '@lace/common';
3+
import { Button, PostHogAction } from '@lace/common';
44
import { useTranslation } from 'react-i18next';
55
import { Layout } from './Layout';
66
import { sectionTitle, DAPP_VIEWS } from '../config';
@@ -19,6 +19,8 @@ import { useRedirection } from '@hooks';
1919
import { dAppRoutePaths } from '@routes';
2020
import { useWalletStore } from '@stores';
2121
import * as HardwareLedger from '../../../../../../node_modules/@cardano-sdk/hardware-ledger/dist/cjs';
22+
import { useAnalyticsContext } from '@providers';
23+
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
2224

2325
const INDENT_SPACING = 2;
2426
const DAPP_TOAST_DURATION = 50;
@@ -46,6 +48,7 @@ export const DappConfirmData = (): React.ReactElement => {
4648
const redirectToSignSuccess = useRedirection(dAppRoutePaths.dappTxSignSuccess);
4749
const [isConfirmingTx, setIsConfirmingTx] = useState<boolean>();
4850
const [dappInfo, setDappInfo] = useState<Wallet.DappInfo>();
51+
const analytics = useAnalyticsContext();
4952
const isUsingHardwareWallet = useMemo(
5053
() => getKeyAgentType() !== Wallet.KeyManagement.KeyAgentType.InMemory,
5154
[getKeyAgentType]
@@ -130,10 +133,12 @@ export const DappConfirmData = (): React.ReactElement => {
130133
}
131134
}, [setIsConfirmingTx, redirectToSignFailure, redirectToSignSuccess]);
132135

133-
const confirmationCallback = useCallback(
134-
() => (isUsingHardwareWallet ? signWithHardwareWallet() : setNextView()),
135-
[isUsingHardwareWallet, signWithHardwareWallet, setNextView]
136-
);
136+
const confirmationCallback = useCallback(() => {
137+
analytics?.sendEventToPostHog(PostHogAction.SendTransactionDataReviewTransactionClick, {
138+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
139+
});
140+
isUsingHardwareWallet ? signWithHardwareWallet() : setNextView();
141+
}, [isUsingHardwareWallet, signWithHardwareWallet, setNextView, analytics]);
137142

138143
return (
139144
<Layout pageClassname={styles.spaceBetween} title={t(sectionTitle[DAPP_VIEWS.CONFIRM_DATA])}>

apps/browser-extension-wallet/src/features/dapp/components/ConfirmTransaction.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect, useMemo, useCallback } from 'react';
2-
import { Button, useObservable } from '@lace/common';
2+
import { Button, PostHogAction, useObservable } from '@lace/common';
33
import { useTranslation } from 'react-i18next';
44
import { DappTransaction } from '@lace/core';
55
import { Layout } from './Layout';
@@ -23,6 +23,8 @@ import { of } from 'rxjs';
2323
import { CardanoTxOut } from '@src/types';
2424
import { getAssetsInformation, TokenInfo } from '@src/utils/get-assets-information';
2525
import * as HardwareLedger from '../../../../../../node_modules/@cardano-sdk/hardware-ledger/dist/cjs';
26+
import { useAnalyticsContext } from '@providers';
27+
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
2628

2729
const DAPP_TOAST_DURATION = 50;
2830

@@ -49,6 +51,7 @@ export const ConfirmTransaction = withAddressBookContext((): React.ReactElement
4951
blockchainProvider: { assetProvider }
5052
} = useWalletStore();
5153
const { list: addressList } = useAddressBookContext();
54+
const analytics = useAnalyticsContext();
5255

5356
const [tx, setTx] = useState<Wallet.Cardano.Tx>();
5457
const assets = useObservable<TokenInfo | null>(inMemoryWallet.assetInfo$);
@@ -231,6 +234,14 @@ export const ConfirmTransaction = withAddressBookContext((): React.ReactElement
231234
adaFollowingNumericValue: t('general.adaFollowingNumericValue')
232235
};
233236

237+
const onConfirm = () => {
238+
analytics.sendEventToPostHog(PostHogAction.SendTransactionSummaryConfirmClick, {
239+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
240+
});
241+
242+
isUsingHardwareWallet ? signWithHardwareWallet() : setNextView();
243+
};
244+
234245
return (
235246
<Layout pageClassname={styles.spaceBetween} title={t(sectionTitle[DAPP_VIEWS.CONFIRM_TX])}>
236247
{tx && txSummary ? (
@@ -245,9 +256,7 @@ export const ConfirmTransaction = withAddressBookContext((): React.ReactElement
245256
)}
246257
<div className={styles.actions}>
247258
<Button
248-
onClick={async () => {
249-
isUsingHardwareWallet ? signWithHardwareWallet() : setNextView();
250-
}}
259+
onClick={onConfirm}
251260
disabled={!!errorMessage}
252261
loading={isUsingHardwareWallet && isConfirmingTx}
253262
data-testid="dapp-transaction-confirm"

apps/browser-extension-wallet/src/features/dapp/components/DappTransactionFail.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { Button } from '@lace/common';
3+
import { Button, PostHogAction } from '@lace/common';
44
import Fail from '../../../assets/icons/exclamation-circle.svg';
55
import styles from './Layout.module.scss';
66
import { Image } from 'antd';
7+
import { useAnalyticsContext } from '@providers';
8+
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
79

810
export const DappTransactionFail = (): React.ReactElement => {
911
const { t } = useTranslation();
12+
const analytics = useAnalyticsContext();
13+
const onClose = async () => {
14+
await analytics?.sendEventToPostHog(PostHogAction.SendSomethingWentWrongCancelClick, {
15+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
16+
});
17+
window.close();
18+
};
19+
20+
useEffect(() => {
21+
analytics?.sendEventToPostHog(PostHogAction.SendSomethingWentWrongView, {
22+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
23+
});
24+
}, [analytics]);
1025

1126
return (
1227
<div data-testid="dapp-sign-tx-fail" className={styles.noWalletContainer}>
@@ -16,7 +31,7 @@ export const DappTransactionFail = (): React.ReactElement => {
1631
<div className={styles.description}>{t('dapp.sign.failure.description')}</div>
1732
</div>
1833
<div className={styles.footer}>
19-
<Button onClick={() => window.close()} color="secondary" className={styles.footerBtn}>
34+
<Button onClick={onClose} color="secondary" className={styles.footerBtn}>
2035
{t('general.button.cancel')}
2136
</Button>
2237
</div>

apps/browser-extension-wallet/src/features/dapp/components/DappTransactionSuccess.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { Button } from '@lace/common';
3+
import { Button, PostHogAction } from '@lace/common';
44
import { Image } from 'antd';
55
import Success from '../../../assets/icons/success-staking.svg';
66
import styles from './Layout.module.scss';
7+
import { useAnalyticsContext } from '@providers';
8+
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
79

810
export const DappTransactionSuccess = (): React.ReactElement => {
11+
const analytics = useAnalyticsContext();
912
const { t } = useTranslation();
1013

14+
const onClose = async () => {
15+
await analytics?.sendEventToPostHog(PostHogAction.SendAllDoneCloseClick, {
16+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
17+
});
18+
window.close();
19+
};
20+
21+
useEffect(() => {
22+
analytics?.sendEventToPostHog(PostHogAction.SendAllDoneView, {
23+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
24+
});
25+
}, [analytics]);
26+
1127
return (
1228
<div data-testid="dapp-sign-tx-success" className={styles.noWalletContainer}>
1329
<div className={styles.noWalletContent}>
@@ -20,11 +36,7 @@ export const DappTransactionSuccess = (): React.ReactElement => {
2036
</div>
2137
</div>
2238
<div className={styles.footer}>
23-
<Button
24-
data-testid="dapp-sign-tx-success-close-button"
25-
className={styles.footerBtn}
26-
onClick={() => window.close()}
27-
>
39+
<Button data-testid="dapp-sign-tx-success-close-button" className={styles.footerBtn} onClick={onClose}>
2840
{t('general.button.close')}
2941
</Button>
3042
</div>

apps/browser-extension-wallet/src/features/dapp/components/SignTransaction.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useState, useMemo } from 'react';
22
import { Spin } from 'antd';
33
import { Wallet } from '@lace/cardano';
44
import { useTranslation } from 'react-i18next';
5-
import { Button, inputProps, Password } from '@lace/common';
5+
import { Button, inputProps, Password, PostHogAction } from '@lace/common';
66
import { useWalletStore } from '@stores';
77
import { useRedirection, useWalletManager } from '@hooks';
88
import { dAppRoutePaths } from '@routes';
@@ -14,6 +14,8 @@ import { DAPP_CHANNELS } from '@src/utils/constants';
1414
import { runtime } from 'webextension-polyfill';
1515
import { UserPromptService } from '@lib/scripts/background/services';
1616
import { of } from 'rxjs';
17+
import { useAnalyticsContext } from '@providers';
18+
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
1719

1820
export const SignTransaction = (): React.ReactElement => {
1921
const { t } = useTranslation();
@@ -26,6 +28,7 @@ export const SignTransaction = (): React.ReactElement => {
2628
const [password, setPassword] = useState<string>();
2729
const [validPassword, setValidPassword] = useState<boolean>();
2830
const { keyAgentData } = useWalletStore();
31+
const analytics = useAnalyticsContext();
2932

3033
const handleVerifyPass = useCallback(async () => {
3134
setIsLoading(true);
@@ -52,10 +55,12 @@ export const SignTransaction = (): React.ReactElement => {
5255
}
5356
}, [password, redirectToSignFailure, keyAgentData]);
5457

55-
const onConfirm = useCallback(
56-
() => executeWithPassword(password, handleVerifyPass, false),
57-
[executeWithPassword, handleVerifyPass, password]
58-
);
58+
const onConfirm = useCallback(() => {
59+
analytics.sendEventToPostHog(PostHogAction.SendTransactionConfirmationConfirmClick, {
60+
[TX_CREATION_TYPE_KEY]: TxCreationType.External
61+
});
62+
executeWithPassword(password, handleVerifyPass, false);
63+
}, [executeWithPassword, handleVerifyPass, password, analytics]);
5964

6065
const handleChange: inputProps['onChange'] = ({ target: { value } }) => setPassword(value);
6166

apps/browser-extension-wallet/src/features/dapp/components/__tests__/ConfirmTransaction.test.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ import { ConfirmTransaction } from '../ConfirmTransaction';
1313
import '@testing-library/jest-dom';
1414
import { I18nextProvider } from 'react-i18next';
1515
import { StoreProvider } from '@src/stores';
16-
import { AppSettingsProvider, DatabaseProvider, ViewFlowProvider } from '@src/providers';
16+
import {
17+
AnalyticsProvider,
18+
AppSettingsProvider,
19+
BackgroundServiceAPIProvider,
20+
BackgroundServiceAPIProviderProps,
21+
DatabaseProvider,
22+
ViewFlowProvider
23+
} from '@src/providers';
1724
import { APP_MODE_BROWSER } from '@src/utils/constants';
1825
import i18n from '@lib/i18n';
1926
import { BehaviorSubject } from 'rxjs';
2027
import { act } from 'react-dom/test-utils';
2128
import { sendViewsFlowState } from '../../config';
29+
import { PostHogClientProvider } from '@providers/PostHogClientProvider';
30+
import { postHogClientMocks } from '@src/utils/mocks/test-helpers';
2231

2332
const assetInfo$ = new BehaviorSubject(new Map());
2433
const available$ = new BehaviorSubject([]);
@@ -63,19 +72,30 @@ const testIds = {
6372
dappTransactionConfirm: 'dapp-transaction-confirm'
6473
};
6574

75+
const backgroundService = {
76+
getBackgroundStorage: jest.fn(),
77+
setBackgroundStorage: jest.fn()
78+
} as unknown as BackgroundServiceAPIProviderProps['value'];
79+
6680
const getWrapper =
6781
() =>
6882
({ children }: { children: React.ReactNode }) =>
6983
(
70-
<AppSettingsProvider>
71-
<DatabaseProvider>
72-
<StoreProvider appMode={APP_MODE_BROWSER}>
73-
<I18nextProvider i18n={i18n}>
74-
<ViewFlowProvider viewStates={sendViewsFlowState}>{children}</ViewFlowProvider>
75-
</I18nextProvider>
76-
</StoreProvider>
77-
</DatabaseProvider>
78-
</AppSettingsProvider>
84+
<BackgroundServiceAPIProvider value={backgroundService}>
85+
<AppSettingsProvider>
86+
<DatabaseProvider>
87+
<StoreProvider appMode={APP_MODE_BROWSER}>
88+
<PostHogClientProvider postHogCustomClient={postHogClientMocks as any}>
89+
<AnalyticsProvider analyticsDisabled>
90+
<I18nextProvider i18n={i18n}>
91+
<ViewFlowProvider viewStates={sendViewsFlowState}>{children}</ViewFlowProvider>
92+
</I18nextProvider>
93+
</AnalyticsProvider>
94+
</PostHogClientProvider>
95+
</StoreProvider>
96+
</DatabaseProvider>
97+
</AppSettingsProvider>
98+
</BackgroundServiceAPIProvider>
7999
);
80100

81101
describe('Testing ConfirmTransaction component', () => {

apps/browser-extension-wallet/src/providers/AnalyticsProvider/analyticsTracker/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export enum TxRecipientType {
5454
RegularAddress = 'regular address'
5555
}
5656

57+
export const TX_CREATION_TYPE_KEY = 'tx_creation_type';
58+
59+
export enum TxCreationType {
60+
Internal = 'internal',
61+
External = 'external'
62+
}
63+
5764
export type OnboardingFlows = 'create' | 'restore' | 'hw' | 'forgot_password';
5865
export type PostHogActionsKeys =
5966
| 'SETUP_OPTION_CLICK'

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/SendTransactionDrawer/Footer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import {
3030
MatomoEventActions,
3131
MatomoEventCategories,
3232
AnalyticsEventNames,
33-
PostHogAction
33+
PostHogAction,
34+
TxCreationType,
35+
TX_CREATION_TYPE_KEY
3436
} from '@providers/AnalyticsProvider/analyticsTracker';
3537
import { buttonIds } from '@hooks/useEnterKeyPress';
3638
import { AssetPickerFooter } from './AssetPickerFooter';
@@ -105,7 +107,10 @@ export const Footer = withAddressBookContext(
105107
const isSummaryStep = currentSection.currentSection === Sections.SUMMARY;
106108

107109
const sendEventToPostHog = (evtAction: PostHogAction) =>
108-
analytics.sendEventToPostHog(evtAction, { trigger_point: triggerPoint });
110+
analytics.sendEventToPostHog(evtAction, {
111+
trigger_point: triggerPoint,
112+
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
113+
});
109114

110115
const sendAnalytics = useCallback(() => {
111116
switch (currentSection.currentSection) {

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/SendTransactionDrawer/HeaderView.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import {
3333
MatomoEventActions,
3434
MatomoEventCategories,
3535
AnalyticsEventNames,
36-
PostHogAction
36+
PostHogAction,
37+
TX_CREATION_TYPE_KEY,
38+
TxCreationType
3739
} from '@providers/AnalyticsProvider/analyticsTracker';
3840

3941
import { useWalletStore } from '@src/stores';
@@ -182,9 +184,15 @@ export const HeaderNavigation = ({ isPopupView }: HeaderNavigationProps): React.
182184

183185
const onCrossIconClick = () => {
184186
if (section.currentSection === Sections.SUCCESS_TX) {
185-
analytics.sendEventToPostHog(PostHogAction.SendAllDoneXClick, { trigger_point: triggerPoint });
187+
analytics.sendEventToPostHog(PostHogAction.SendAllDoneXClick, {
188+
trigger_point: triggerPoint,
189+
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
190+
});
186191
} else if (section.currentSection === Sections.FAIL_TX) {
187-
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongXClick, { trigger_point: triggerPoint });
192+
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongXClick, {
193+
trigger_point: triggerPoint,
194+
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
195+
});
188196
}
189197
onClose();
190198
};

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/TransactionFail.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { ResultMessage } from '@components/ResultMessage';
44
import { useAnalyticsContext } from '@providers';
5-
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';
5+
import { PostHogAction, TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
66
import styles from './TransactionSuccessView.module.scss';
77
import { useAnalyticsSendFlowTriggerPoint } from '../store';
88

@@ -12,8 +12,11 @@ export const TransactionFail = (): React.ReactElement => {
1212
const { triggerPoint } = useAnalyticsSendFlowTriggerPoint();
1313

1414
useEffect(() => {
15-
// eslint-disable-next-line camelcase
16-
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongView, { trigger_point: triggerPoint });
15+
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongView, {
16+
// eslint-disable-next-line camelcase
17+
trigger_point: triggerPoint,
18+
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
19+
});
1720
// eslint-disable-next-line react-hooks/exhaustive-deps
1821
}, []);
1922

0 commit comments

Comments
 (0)