Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [lw-11532] add analytics for shared wallet #1462

Merged
merged 9 commits into from
Oct 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,25 @@ export const TransactionCTAsBox = (): React.ReactElement => {
};

const openSend = () => {
// eslint-disable-next-line camelcase
analytics.sendEventToPostHog(PostHogAction.SendClick, { trigger_point: SendFlowTriggerPoints.SEND_BUTTON });
isSharedWallet
? analytics.sendEventToPostHog(PostHogAction.SharedWalletsSendClick)
: // eslint-disable-next-line camelcase
analytics.sendEventToPostHog(PostHogAction.SendClick, { trigger_point: SendFlowTriggerPoints.SEND_BUTTON });
openSendTransactionDrawer();
setTriggerPoint(SendFlowTriggerPoints.SEND_BUTTON);
};

const onCoSignClick = async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCosignClick);
openCoSignTransactionDrawer();
};
greatertomi marked this conversation as resolved.
Show resolved Hide resolved

return (
<TransactionCTAs
buttonClassName={styles.btn}
onSendClick={openSend}
onReceiveClick={openReceive}
onCoSignClick={isSharedWallet ? openCoSignTransactionDrawer : undefined}
onCoSignClick={isSharedWallet ? onCoSignClick : undefined}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { useBuiltTxState } from '../store';
import { Serialization } from '@cardano-sdk/core';
import { Wallet } from '@lace/cardano';
import { useWalletState } from '@hooks/useWalletState';
import { useAnalyticsContext } from '@providers';
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';

export const ImportSharedWalletTransaction = (): JSX.Element => {
const [config] = useDrawer();
const { setBuiltTxData } = useBuiltTxState();
const walletState = useWalletState();
const analytics = useAnalyticsContext();

return (
<CoSignEntry
onImportError={() => analytics.sendEventToPostHog(PostHogAction.SharedWalletsCosignTxImportJsonError)}
// eslint-disable-next-line react/jsx-handler-names
onCancel={config.onClose}
onContinue={async (txData) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-magic-numbers */
/* eslint-disable camelcase */
/* eslint-disable max-statements */
/* eslint-disable unicorn/no-null */
Expand Down Expand Up @@ -93,38 +94,62 @@ export const Footer = withAddressBookContext(

const isSummaryStep = currentSection.currentSection === Sections.SUMMARY;

const sendEventToPostHog = (evtAction: PostHogAction) =>
analytics.sendEventToPostHog(evtAction, {
const sendEventToPostHog = async (evtAction: PostHogAction) =>
await analytics.sendEventToPostHog(evtAction, {
greatertomi marked this conversation as resolved.
Show resolved Hide resolved
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
});

const sendAnalytics = useCallback(() => {
const sendAnalytics = useCallback(async () => {
switch (currentSection.currentSection) {
case Sections.FORM: {
sendEventToPostHog(PostHogAction.SendTransactionDataReviewTransactionClick);
await sendEventToPostHog(
PostHogAction[
isSharedWallet ? 'SharedWalletsSendTxDataReviewTxClick' : 'SendTransactionDataReviewTransactionClick'
]
);
break;
}
case Sections.SUMMARY: {
sendEventToPostHog(PostHogAction.SendTransactionSummaryConfirmClick);
await (builtTxData.importedSharedWalletTx
? sendEventToPostHog(PostHogAction.SharedWalletsCosignTxSummaryConfirmClick)
: sendEventToPostHog(
PostHogAction[
isSharedWallet ? 'SharedWalletsSendTxSummaryConfirmClick' : 'SendTransactionSummaryConfirmClick'
]
));
break;
}
case Sections.CONFIRMATION: {
sendEventToPostHog(PostHogAction.SendTransactionConfirmationConfirmClick);
await sendEventToPostHog(
PostHogAction[
isSharedWallet ? 'SharedWalletsSendTxConfirmationConfirmClick' : 'SendTransactionConfirmationConfirmClick'
]
);
break;
}
case Sections.SUCCESS_TX: {
sendEventToPostHog(PostHogAction.SendAllDoneViewTransactionClick);
await sendEventToPostHog(
PostHogAction[isSharedWallet ? 'SharedWalletsSendAllDoneViewTxClick' : 'SendAllDoneViewTransactionClick']
);
break;
}
case Sections.UNAUTHORIZED_TX:
case Sections.FAIL_TX: {
sendEventToPostHog(PostHogAction.SendSomethingWentWrongBackClick);
await sendEventToPostHog(
PostHogAction[
isSharedWallet ? 'SharedWalletsSendSomethingWentWrongBackClick' : 'SendSomethingWentWrongBackClick'
]
);
break;
}
case Sections.IMPORT_SHARED_WALLET_TRANSACTION_JSON: {
await sendEventToPostHog(PostHogAction.SharedWalletsCosignTxContinueClick);
break;
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentSection.currentSection, isPopupView]);
}, [currentSection.currentSection, isPopupView, isSharedWallet]);

const handleReviewAddress = useCallback(
(result: keyof typeof ACTIONS) => {
Expand Down Expand Up @@ -274,8 +299,8 @@ export const Footer = withAddressBookContext(
};
}, [setSection, setSubmitingTxState, isPopupView]);

const onConfirm = useCallback(() => {
sendAnalytics();
const onConfirm = useCallback(async () => {
greatertomi marked this conversation as resolved.
Show resolved Hide resolved
await sendAnalytics();
const isConfirmPass = currentSection.currentSection === Sections.CONFIRMATION;
const txHasSucceeded = currentSection.currentSection === Sections.SUCCESS_TX;
const txHasFailed =
Expand All @@ -301,7 +326,8 @@ export const Footer = withAddressBookContext(
return handleVerifyPass();
}
case txHasSucceeded: {
return onCloseSubmitedTransaction();
// Tab is closed sooner than analytics are sent
return setTimeout(() => onCloseSubmitedTransaction(), 300);
}
case txHasFailed: {
setSubmitingTxState({ isPasswordValid: true });
Expand All @@ -326,11 +352,31 @@ export const Footer = withAddressBookContext(
setSubmitingTxState
]);

const handleClose = () => {
if (currentSection.currentSection === Sections.SUCCESS_TX) {
sendEventToPostHog(PostHogAction.SendAllDoneCloseClick);
} else if (currentSection.currentSection === Sections.FAIL_TX) {
sendEventToPostHog(PostHogAction.SendSomethingWentWrongCancelClick);
const handleClose = async () => {
greatertomi marked this conversation as resolved.
Show resolved Hide resolved
switch (currentSection.currentSection) {
case Sections.SUCCESS_TX: {
sendEventToPostHog(
greatertomi marked this conversation as resolved.
Show resolved Hide resolved
PostHogAction[isSharedWallet ? 'SharedWalletsSendAllDoneCloseClick' : 'SendAllDoneCloseClick']
);
break;
}
case Sections.FAIL_TX: {
sendEventToPostHog(
PostHogAction[
isSharedWallet ? 'SharedWalletsSendSomethingWentWrongCancelClick' : 'SendSomethingWentWrongCancelClick'
]
);
break;
}
case Sections.IMPORT_SHARED_WALLET_TRANSACTION_JSON: {
sendEventToPostHog(PostHogAction.SharedWalletsCosignTxCancelClick);
break;
}
case Sections.SUMMARY: {
sendEventToPostHog(PostHogAction.SharedWalletsCosignTxSummaryCancelClick);
break;
}
// No default
}

onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const HeaderNavigation = ({
const [isMultipleSelectionAvailable, setMultipleSelection] = useMultipleSelection();
const { selectedTokenList, resetTokenList } = useSelectedTokenList();
const { triggerPoint } = useAnalyticsSendFlowTriggerPoint();
const { isSharedWallet } = useWalletStore();

const shouldRenderArrow = isPopupView
? [...sectionsWithArrowIcon, Sections.FORM].includes(section.currentSection)
Expand Down Expand Up @@ -169,15 +170,21 @@ export const HeaderNavigation = ({

const onCrossIconClick = () => {
if (section.currentSection === Sections.SUCCESS_TX) {
analytics.sendEventToPostHog(PostHogAction.SendAllDoneXClick, {
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
});
analytics.sendEventToPostHog(
PostHogAction[isSharedWallet ? 'SharedWalletsSendAllDoneXClick' : 'SendAllDoneXClick'],
{
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
}
);
} else if (section.currentSection === Sections.FAIL_TX || section.currentSection === Sections.UNAUTHORIZED_TX) {
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongXClick, {
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
});
analytics.sendEventToPostHog(
PostHogAction[isSharedWallet ? 'SharedWalletsSendSomethingWentWrongXClick' : 'SendSomethingWentWrongXClick'],
{
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
}
);
}
onClose();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PostHogAction, TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/
import styles from './TransactionSuccessView.module.scss';
import { useAnalyticsSendFlowTriggerPoint } from '../store';
import { WarningBanner } from '@lace/common';
import { useWalletStore } from '@src/stores';

interface TransactionFailProps {
showCustomApiBanner?: boolean;
Expand All @@ -15,13 +16,17 @@ export const TransactionFail = ({ showCustomApiBanner = false }: TransactionFail
const { t } = useTranslation();
const analytics = useAnalyticsContext();
const { triggerPoint } = useAnalyticsSendFlowTriggerPoint();
const { isSharedWallet } = useWalletStore();

useEffect(() => {
analytics.sendEventToPostHog(PostHogAction.SendSomethingWentWrongView, {
// eslint-disable-next-line camelcase
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
});
analytics.sendEventToPostHog(
PostHogAction[isSharedWallet ? 'SharedWalletsSendSomethingWentWrongView' : 'SendSomethingWentWrongView'],
{
// eslint-disable-next-line camelcase
trigger_point: triggerPoint,
[TX_CREATION_TYPE_KEY]: TxCreationType.Internal
}
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const TransactionSuccessView = ({ footerSlot }: { footerSlot?: React.Reac
);
const recipientTypesUnique = uniq(recipientTypes);
const recipientSourceUnique = uniq(recipientSources);
analytics.sendEventToPostHog(PostHogAction.SendAllDoneView, {
analytics.sendEventToPostHog(PostHogAction[isSharedWallet ? 'SharedWalletsSendAllDoneView' : 'SendAllDoneView'], {
// eslint-disable-next-line camelcase
trigger_point: triggerPoint,
tokens: customAnalyticsProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { useWalletStore } from '@stores';
import { WalletType } from '@cardano-sdk/web-extension';
import { config } from '@src/config';
import { Wallet } from '@lace/cardano';
import { useAnalyticsContext } from '@providers';
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker';

const { CHAIN } = config();
const DEFAULT_CHAIN_ID = Wallet.Cardano.ChainIds[CHAIN];
Expand All @@ -29,6 +31,7 @@ type CreateWalletParams = {
};

export const SharedWallet = (): JSX.Element => {
const analytics = useAnalyticsContext();
const history = useHistory();
const { walletRepository, generateSharedWalletKey, saveSharedWalletKey, createInMemorySharedWallet } =
useWalletManager();
Expand Down Expand Up @@ -89,6 +92,13 @@ export const SharedWallet = (): JSX.Element => {
activeWalletName={walletInfo?.name || ''}
activeWalletType={activeWalletType}
generateKey={generateKey}
onGenerateKeys={async () =>
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsGenerateKeyClick)
}
onCopyKeys={async () =>
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsGenerateCopyKeyClick)
}
onClose={async () => await analytics.sendEventToPostHog(PostHogAction.SharedWalletsGenerateCloseClick)}
greatertomi marked this conversation as resolved.
Show resolved Hide resolved
navigateToParentFlow={() => history.push(walletRoutePaths.sharedWallet.root)}
/>
)}
Expand All @@ -105,6 +115,29 @@ export const SharedWallet = (): JSX.Element => {
exitTheFlow={() => history.push(walletRoutePaths.sharedWallet.root)}
sharedWalletKey={sharedWalletKey}
onCreateSharedWallet={handleCreateWallet}
onWalletNameNextClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateWalletNameNextClick);
}}
onAddCosignersNextClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateAddCosignersNextClick);
}}
onImportantInfoNextClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateImportantInfoContinueClick);
}}
onImportantInfoBackClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateImportantInfoBackClick);
}}
onDefineQuorumNextClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateDefineQuorumNextClick);
}}
onDefineQuorumDownloadClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateDefineQuorumDownloadClick);
}}
onOpenSharedWalletClick={async () => {
await analytics.sendEventToPostHog(
PostHogAction.SharedWalletsCreateShareWalletDetailsOpenSharedWalletClick
);
}}
/>
)}
/>
Expand All @@ -115,10 +148,16 @@ export const SharedWallet = (): JSX.Element => {
path={walletRoutePaths.sharedWallet.import}
render={() => (
<SharedWalletRestorationFlow
onRestoreSharedWallet={handleCreateWallet}
onRestoreSharedWallet={async (data: CreateWalletParams) => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsLocateWalletOpenWalletClick);
await handleCreateWallet(data);
}}
sharedKeys={sharedWalletKey}
exitTheFlow={() => history.push(walletRoutePaths.sharedWallet.root)}
navigateToAppHome={() => setBackgroundPage()}
onImportJsonError={async () =>
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsLocateWalletImportJsonError)
}
/>
)}
/>
Expand All @@ -128,9 +167,18 @@ export const SharedWallet = (): JSX.Element => {
path={walletRoutePaths.sharedWallet.root}
render={() => (
<AddSharedWalletMainPageFlow
onCreateSharedWalletClick={() => history.push(walletRoutePaths.sharedWallet.create)}
onImportSharedWalletClick={() => history.push(walletRoutePaths.sharedWallet.import)}
onKeysGenerateClick={() => history.push(walletRoutePaths.sharedWallet.generateKeys)}
onCreateSharedWalletClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsCreateClick);
history.push(walletRoutePaths.sharedWallet.create);
}}
onImportSharedWalletClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsConnectClick);
history.push(walletRoutePaths.sharedWallet.import);
}}
onKeysGenerateClick={async () => {
await analytics.sendEventToPostHog(PostHogAction.SharedWalletsGenerateClick);
history.push(walletRoutePaths.sharedWallet.generateKeys);
}}
sharedWalletKey={sharedWalletKey}
/>
)}
Expand Down
Loading
Loading