Skip to content

Commit

Permalink
[FIX]: Analytics LedgerSync
Browse files Browse the repository at this point in the history
  • Loading branch information
mcayuelas-ledger committed Sep 5, 2024
1 parent 917045c commit ca3c1a3
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-feet-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Fix Analytics LedgerSync
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ViewProps = {
doesNotHaveAccount?: boolean;
onClickAdd: () => void;
onClickImport: () => void;
setWalletSyncDrawerVisible?: () => void;
onClickImportLedgerSync?: () => void;
};

type AddAccountScreenProps = {
Expand All @@ -26,7 +26,7 @@ function View({
isReadOnlyModeEnabled,
onClickAdd,
onClickImport,
setWalletSyncDrawerVisible,
onClickImportLedgerSync,
doesNotHaveAccount,
}: ViewProps) {
const { t } = useTranslation();
Expand All @@ -45,7 +45,7 @@ function View({
rows.push({
titleKey: "addAccountsModal.drawer.walletSync.title",
descriptionKey: "addAccountsModal.drawer.walletSync.description",
onPress: setWalletSyncDrawerVisible,
onPress: onClickImportLedgerSync,
icon: <Icons.QrCode color={"primary.c80"} />,
testID: "add-accounts-modal-wallet-sync-button",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
type AddAccountScreenProps = {
currency?: CryptoCurrency | TokenCurrency | null;
onClose?: () => void;
setWalletSyncDrawerVisible?: () => void;
};

const useSelectAddAccountMethodViewModel = ({ currency, onClose }: AddAccountScreenProps) => {
const useSelectAddAccountMethodViewModel = ({
currency,
onClose,
setWalletSyncDrawerVisible,
}: AddAccountScreenProps) => {
const navigation = useNavigation<BaseNavigation>();
const walletSyncFeatureFlag = useFeature("llmWalletSync");

Expand Down Expand Up @@ -42,6 +47,11 @@ const useSelectAddAccountMethodViewModel = ({ currency, onClose }: AddAccountScr
navigation.navigate(NavigatorName.ImportAccounts);
}, [navigation, trackButtonClick, onClose]);

const onClickImportLedgerSync = useCallback(() => {
trackButtonClick("Import via another Ledger Live app");
setWalletSyncDrawerVisible?.();
}, [trackButtonClick, setWalletSyncDrawerVisible]);

const onClickAdd = useCallback(() => {
trackButtonClick("With your Ledger");
onClose?.();
Expand All @@ -53,6 +63,7 @@ const useSelectAddAccountMethodViewModel = ({ currency, onClose }: AddAccountScr
isReadOnlyModeEnabled,
onClickAdd,
onClickImport,
onClickImportLedgerSync,
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from "react";
import React, { useCallback, useMemo } from "react";
import { createStackNavigator } from "@react-navigation/stack";
import { useTheme } from "styled-components/native";
import { ScreenName } from "~/const";
Expand All @@ -17,6 +17,10 @@ import { WalletSyncManageInstanceDeletionSuccess } from "./screens/ManageInstanc
import { LedgerSyncDeepLinkHandler } from "./screens/LedgerSyncDeepLinkHandler";
import { NavigationHeaderCloseButton } from "~/components/NavigationHeaderCloseButton";
import { useClose } from "./hooks/useClose";
import { track } from "~/analytics";
import { AnalyticsPage } from "./hooks/useLedgerSyncAnalytics";
import { NavigationHeaderBackButton } from "~/components/NavigationHeaderBackButton";
import { NavigationProp } from "@react-navigation/native";

const Stack = createStackNavigator<WalletSyncNavigatorStackParamList>();

Expand All @@ -27,6 +31,17 @@ export default function WalletSyncNavigator() {
useInitMemberCredentials();
const close = useClose();

const onHeaderBackButtonPress = useCallback(
(navigation: NavigationProp<ReactNavigation.RootParamList>) => {
track("button_clicked", {
button: "Back",
page: AnalyticsPage.LedgerSyncSettings,
});
navigation.goBack();
},
[],
);

return (
<Stack.Navigator screenOptions={stackNavConfig}>
<Stack.Screen
Expand Down Expand Up @@ -68,10 +83,13 @@ export default function WalletSyncNavigator() {
<Stack.Screen
name={ScreenName.WalletSyncActivated}
component={WalletSyncManage}
options={{
options={({ navigation }) => ({
title: t("walletSync.title"),
headerRight: () => null,
}}
headerLeft: () => (
<NavigationHeaderBackButton onPress={() => onHeaderBackButtonPress(navigation)} />
),
})}
/>

<Stack.Screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
useLedgerSyncAnalytics,
AnalyticsButton,
AnalyticsPage,
AnalyticsFlow,
} from "LLM/features/WalletSync/hooks/useLedgerSyncAnalytics";

type Props = {
Expand All @@ -21,7 +20,7 @@ const Actions = ({ onPressSyncAccounts, onPressHasAlreadyCreatedAKey }: Props) =
onClickTrack({
button: AnalyticsButton.SyncYourAccounts,
page: AnalyticsPage.ActivateLedgerSync,
flow: AnalyticsFlow.LedgerSync,
hasFlow: true,
});
onPressSyncAccounts();
};
Expand All @@ -30,7 +29,7 @@ const Actions = ({ onPressSyncAccounts, onPressHasAlreadyCreatedAKey }: Props) =
onClickTrack({
button: AnalyticsButton.AlreadyCreatedKey,
page: AnalyticsPage.ActivateLedgerSync,
flow: AnalyticsFlow.LedgerSync,
hasFlow: true,
});
onPressHasAlreadyCreatedAKey();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export enum AnalyticsPage {
RemoveInstanceWrongDevice = "Remove instance wrong device connected",
RemoveInstanceSuccess = "Instance removal success",
ManageBackup = "Manage key",
ConfirmDeleteBackup = "Confirm delete backup",
ConfirmDeleteBackup = "Confirm delete key",
DeleteBackupSuccess = "Delete key success",
SyncWithNoKey = "Sync with no key",
LedgerSyncActivated = "Ledger Sync activated",
Expand All @@ -28,6 +28,7 @@ export enum AnalyticsPage {
ScanAttemptWithDifferentBackups = "Scan attempt with different backups",
OnBoardingQRCodeNoBackup = "Onboarding no backup detected",
OnBoardingDeviceNoBackup = "Onboarding this Ledger does not secure a backup",
OnboardingAccessExistingWallet = "Onboarding access existing wallet",
}

export enum AnalyticsFlow {
Expand All @@ -40,7 +41,7 @@ export enum AnalyticsButton {
Close = "Close",
UseYourLedger = "Use your Ledger",
ScanQRCode = "Scan a QR code",
SyncWithAnotherLedgerLive = "Sync with another Ledger Live",
SyncWithAnotherLedgerLive = "Sync with another Ledger Live app",
ShowQRCode = "Show QR",
TryAgain = "Try again",
Synchronize = "Synchronize",
Expand All @@ -62,12 +63,12 @@ export enum AnalyticsButton {
type OnClickTrack = {
button: (typeof AnalyticsButton)[keyof typeof AnalyticsButton];
page: (typeof AnalyticsPage)[keyof typeof AnalyticsPage];
flow?: (typeof AnalyticsFlow)[keyof typeof AnalyticsFlow];
hasFlow?: boolean;
};

export function useLedgerSyncAnalytics() {
const onClickTrack = ({ button, page, flow = AnalyticsFlow.LedgerSync }: OnClickTrack) => {
track("button_clicked", { button, page, flow });
const onClickTrack = ({ button, page, hasFlow = false }: OnClickTrack) => {
track("button_clicked", { button, page, flow: hasFlow ? AnalyticsFlow.LedgerSync : undefined });
};

return { onClickTrack };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,42 @@ export type SpecificProps = {
secondaryAction?: () => void;
};

type AnalyticsProps = {
page: AnalyticsPage;
hasFlow: boolean;
button?: AnalyticsButton;
};
export function useSpecificError({ primaryAction, secondaryAction }: SpecificProps) {
const { onClickTrack } = useLedgerSyncAnalytics();
const { t } = useTranslation();
const { colors } = useTheme();

const onTryAgain = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.UseAnother, page });
const onTryAgain = (props: AnalyticsProps) => {
onClickTrack({ button: props.button ?? AnalyticsButton.UseAnother, ...props });
};

const onTryAnotherLedger = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.TryAnotherLedger, page });
const onTryAnotherLedger = (props: AnalyticsProps) => {
onClickTrack({ button: AnalyticsButton.TryAnotherLedger, ...props });
};

const onGoToDelete = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.DeleteKey, page });
const onGoToDelete = (props: AnalyticsProps) => {
onClickTrack({ button: AnalyticsButton.DeleteKey, ...props });
};

const onUnderstood = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.Understand, page });
const onUnderstood = (props: AnalyticsProps) => {
onClickTrack({ button: AnalyticsButton.Understand, ...props });
};

const onCancel = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.Cancel, page });
const onCancel = (props: AnalyticsProps) => {
onClickTrack({ button: AnalyticsButton.Cancel, ...props });
};

const onCreate = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.CreateYourKey, page });
const onCreate = (props: AnalyticsProps) => {
onClickTrack({ button: AnalyticsButton.CreateYourKey, ...props });
};

const ContinueWihtoutSync = (page: AnalyticsPage) => {
onClickTrack({ button: AnalyticsButton.ContinueWihtoutSync, page });
const ContinueWihtoutSync = (props: AnalyticsProps) => {
onClickTrack({ button: AnalyticsButton.ContinueWihtoutSync, ...props });
};

const errorConfig: Record<ErrorReason, ErrorConfig> = {
Expand All @@ -86,11 +91,11 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onTryAgain(AnalyticsPage.RemoveInstanceWrongDevice);
onTryAgain({ page: AnalyticsPage.RemoveInstanceWrongDevice, hasFlow: false });
},
secondaryAction: () => {
secondaryAction?.();
onGoToDelete(AnalyticsPage.RemoveInstanceWrongDevice);
onGoToDelete({ page: AnalyticsPage.RemoveInstanceWrongDevice, hasFlow: false });
},
},
[ErrorReason.AUTO_REMOVE]: {
Expand All @@ -108,11 +113,11 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onUnderstood(AnalyticsPage.AutoRemove);
onUnderstood({ page: AnalyticsPage.AutoRemove, hasFlow: false });
},
secondaryAction: () => {
secondaryAction?.();
onGoToDelete(AnalyticsPage.AutoRemove);
onGoToDelete({ page: AnalyticsPage.AutoRemove, hasFlow: false });
},
},
[ErrorReason.SAME_SEED]: {
Expand All @@ -125,7 +130,7 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onUnderstood(AnalyticsPage.SameSeed);
onUnderstood({ page: AnalyticsPage.SameSeed, hasFlow: false });
},
},
[ErrorReason.OTHER_SEED]: {
Expand All @@ -139,11 +144,11 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
outline: true,
primaryAction: () => {
primaryAction();
onGoToDelete(AnalyticsPage.OtherSeed);
onGoToDelete({ page: AnalyticsPage.OtherSeed, hasFlow: false });
},
secondaryAction: () => {
secondaryAction?.();
onCancel(AnalyticsPage.OtherSeed);
onCancel({ page: AnalyticsPage.OtherSeed, hasFlow: false });
},
},
[ErrorReason.ALREADY_BACKED_SCAN]: {
Expand All @@ -154,7 +159,7 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onUnderstood(AnalyticsPage.ScanAttemptWithSameBackup);
onUnderstood({ page: AnalyticsPage.ScanAttemptWithSameBackup, hasFlow: false });
},
},
[ErrorReason.DIFFERENT_BACKUPS]: {
Expand All @@ -166,7 +171,7 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onGoToDelete(AnalyticsPage.ScanAttemptWithDifferentBackups);
onUnderstood({ page: AnalyticsPage.ScanAttemptWithDifferentBackups, hasFlow: false });
},
},
[ErrorReason.NO_BACKUP]: {
Expand All @@ -178,7 +183,7 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onCreate(AnalyticsPage.SyncWithNoKey);
onCreate({ page: AnalyticsPage.SyncWithNoKey, hasFlow: false });
},
},
[ErrorReason.NO_BACKUP_ONBOARDING_QRCODE]: {
Expand All @@ -191,11 +196,15 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onTryAgain(AnalyticsPage.OnBoardingQRCodeNoBackup);
onTryAgain({
page: AnalyticsPage.OnBoardingQRCodeNoBackup,
hasFlow: false,
button: AnalyticsButton.TryAgain,
});
},
secondaryAction: () => {
secondaryAction?.();
ContinueWihtoutSync(AnalyticsPage.OnBoardingQRCodeNoBackup);
ContinueWihtoutSync({ page: AnalyticsPage.OnBoardingQRCodeNoBackup, hasFlow: false });
},
},
[ErrorReason.NO_BACKUP_ONBOARDING_DEVICE]: {
Expand All @@ -207,11 +216,11 @@ export function useSpecificError({ primaryAction, secondaryAction }: SpecificPro
buttonType: "main" as ButtonProps["type"],
primaryAction: () => {
primaryAction();
onTryAnotherLedger(AnalyticsPage.OnBoardingDeviceNoBackup);
onTryAnotherLedger({ page: AnalyticsPage.OnBoardingDeviceNoBackup, hasFlow: false });
},
secondaryAction: () => {
secondaryAction?.();
ContinueWihtoutSync(AnalyticsPage.OnBoardingDeviceNoBackup);
ContinueWihtoutSync({ page: AnalyticsPage.OnBoardingDeviceNoBackup, hasFlow: false });
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function View({
<TrackScreen />
<QueuedDrawer
isRequestingToBeOpened={isOpen}
onClose={onCloseDrawer}
onClose={hasCustomHeader ? undefined : onCloseDrawer}
CustomHeader={hasCustomHeader ? CustomDrawerHeader : undefined}
hasBackButton={canGoBack}
onBack={goBackToPreviousStep}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const WalletSyncManage = () => {

const goToManageBackup = () => {
manageKeyHook.openDrawer();
onClickTrack({ button: AnalyticsButton.ManageKey, page: AnalyticsPage.LedgerSyncSettings });
onClickTrack({
button: AnalyticsButton.ManageKey,
page: AnalyticsPage.LedgerSyncSettings,
hasFlow: false,
});
};

const goToManageInstances = () => {
Expand All @@ -54,6 +58,7 @@ const WalletSyncManage = () => {
onClickTrack({
button: AnalyticsButton.ManageInstances,
page: AnalyticsPage.LedgerSyncSettings,
hasFlow: false,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const QrCodeMethod = ({
setSelectedOption(option);
const button =
option === Options.SCAN ? AnalyticsButton.ScanQRCode : AnalyticsButton.ShowQRCode;
const page = option === Options.SCAN ? AnalyticsPage.ScanQRCode : AnalyticsPage.ShowQRCode;
const page = option === Options.SCAN ? AnalyticsPage.ShowQRCode : AnalyticsPage.ScanQRCode;
onClickTrack({
button,
page,
Expand Down
Loading

0 comments on commit ca3c1a3

Please sign in to comment.