Skip to content

Commit 07e9f1c

Browse files
authored
fix: [lw-12550] add missing posthog events for btc wallet
1 parent 73f5c76 commit 07e9f1c

File tree

3 files changed

+57
-11
lines changed
  • apps/browser-extension-wallet/src
    • components/MainMenu/DropdownMenuOverlay/components
    • providers/AnalyticsProvider/analyticsTracker
    • views/bitcoin-mode/features/send/components

3 files changed

+57
-11
lines changed

apps/browser-extension-wallet/src/components/MainMenu/DropdownMenuOverlay/components/UserInfo.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { WalletStatusContainer } from '@components/WalletStatus';
1111
import { UserAvatar } from './UserAvatar';
1212
import { useGetHandles, useWalletAvatar, useWalletManager } from '@hooks';
1313
import { useAnalyticsContext } from '@providers';
14-
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';
14+
import { PostHogAction, WALLET_TYPE_KEY } from '@providers/AnalyticsProvider/analyticsTracker';
1515
import { ProfileDropdown } from '@input-output-hk/lace-ui-toolkit';
1616
import { AnyBip32Wallet, AnyWallet, Bip32WalletAccount, ScriptWallet, WalletType } from '@cardano-sdk/web-extension';
1717
import { Wallet } from '@lace/cardano';
@@ -145,7 +145,9 @@ export const UserInfo = ({
145145
return;
146146
}
147147

148-
void analytics.sendEventToPostHog(PostHogAction.MultiWalletSwitchWallet);
148+
void analytics.sendEventToPostHog(PostHogAction.MultiWalletSwitchWallet, {
149+
[WALLET_TYPE_KEY]: walletType
150+
});
149151

150152
await activateWallet({
151153
walletId: wallet.walletId,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export enum TxRecipientType {
2424
}
2525

2626
export const TX_CREATION_TYPE_KEY = 'tx_creation_type';
27+
export const WALLET_TYPE_KEY = 'wallet_type';
2728

2829
export enum TxCreationType {
2930
Internal = 'internal',

apps/browser-extension-wallet/src/views/bitcoin-mode/features/send/components/SendFlow.tsx

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable camelcase */
12
/* eslint-disable react/no-multi-comp */
23
/* eslint-disable promise/catch-or-return */
34
/* eslint-disable no-magic-numbers */
@@ -23,6 +24,7 @@ import { DrawerContent } from '@src/views/browser-view/components/Drawer';
2324
import { useTranslation } from 'react-i18next';
2425
import { WarningModal } from '@views/browser/components';
2526
import styles from './SendFlow.module.scss';
27+
import { TxCreationType, TX_CREATION_TYPE_KEY } from '@providers/AnalyticsProvider/analyticsTracker';
2628

2729
const SATS_IN_BTC = 100_000_000;
2830

@@ -157,19 +159,35 @@ export const SendFlow: React.FC = () => {
157159
return false;
158160
}, [pendingTxs, utxos]);
159161

162+
useEffect(() => {
163+
setDrawerConfig({
164+
...config,
165+
onClose: () => {
166+
// eslint-disable-next-line sonarjs/no-small-switch
167+
switch (step) {
168+
case 'DONE':
169+
analytics.sendEventToPostHog(PostHogAction.SendAllDoneCloseClick);
170+
break;
171+
case 'FAILED':
172+
case 'UNAUTHORIZED':
173+
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongXClick);
174+
break;
175+
default:
176+
break;
177+
}
178+
config?.onClose ? config?.onClose() : setDrawerConfig();
179+
}
180+
});
181+
// eslint-disable-next-line react-hooks/exhaustive-deps
182+
}, [analytics, setDrawerConfig, step]);
183+
160184
const {
161185
walletUI: { appMode }
162186
} = useWalletStore();
163187
const isPopupView = appMode === APP_MODE_POPUP;
164188

165189
useEffect(() => {
166190
switch (step) {
167-
case 'AMOUNT':
168-
analytics.sendEventToPostHog(PostHogAction.SendClick);
169-
break;
170-
case 'REVIEW':
171-
analytics.sendEventToPostHog(PostHogAction.SendTransactionDataReviewTransactionClick);
172-
break;
173191
case 'DONE':
174192
analytics.sendEventToPostHog(PostHogAction.SendAllDoneView);
175193
break;
@@ -236,6 +254,7 @@ export const SendFlow: React.FC = () => {
236254

237255
// Step 1 -> 2
238256
const goToReview = (newFeeRate: number) => {
257+
analytics.sendEventToPostHog(PostHogAction.SendTransactionDataReviewTransactionClick);
239258
setFeeRate(newFeeRate);
240259
setUnsignedTransaction(
241260
buildTransaction({
@@ -262,7 +281,13 @@ export const SendFlow: React.FC = () => {
262281
});
263282
};
264283
// Step 2 -> 3
265-
const goToPassword = () => setStep('PASSWORD');
284+
const goToPassword = () => {
285+
analytics.sendEventToPostHog(PostHogAction.SendTransactionSummaryConfirmClick, {
286+
trigger_point: 'send button',
287+
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
288+
});
289+
setStep('PASSWORD');
290+
};
266291

267292
const handleSignTransaction = useCallback(
268293
async (password: Buffer): Promise<Bitcoin.SignedTransaction> | undefined => {
@@ -274,6 +299,7 @@ export const SendFlow: React.FC = () => {
274299

275300
const handleSubmitTx = async (signedTx: Bitcoin.SignedTransaction) => {
276301
try {
302+
analytics.sendEventToPostHog(PostHogAction.SendTransactionConfirmationConfirmClick);
277303
const hash = await bitcoinWallet.submitTransaction(signedTx.hex);
278304
setConfirmationHash(hash);
279305
setStep('DONE');
@@ -335,9 +361,13 @@ export const SendFlow: React.FC = () => {
335361
if (step === 'DONE') {
336362
return (
337363
<TransactionSuccess
338-
onClose={onClose}
364+
onClose={() => {
365+
analytics.sendEventToPostHog(PostHogAction.SendAllDoneCloseClick);
366+
onClose();
367+
}}
339368
isPopupView={isPopupView}
340369
onViewTransaction={() => {
370+
analytics.sendEventToPostHog(PostHogAction.SendAllDoneViewTransactionClick);
341371
setDrawerConfig();
342372
redirectToTransactions();
343373
}}
@@ -347,7 +377,20 @@ export const SendFlow: React.FC = () => {
347377
}
348378

349379
if (step === 'FAILED') {
350-
return <TransactionFailed onClose={onClose} isPopupView={isPopupView} onBack={backToReview} txError={txError} />;
380+
return (
381+
<TransactionFailed
382+
onClose={() => {
383+
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongCancelClick);
384+
onClose();
385+
}}
386+
isPopupView={isPopupView}
387+
onBack={() => {
388+
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongBackClick);
389+
backToReview();
390+
}}
391+
txError={txError}
392+
/>
393+
);
351394
}
352395

353396
return <></>;

0 commit comments

Comments
 (0)