Skip to content

Commit

Permalink
📈 (llm): add analytics for new accounts list
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey committed Jan 7, 2025
1 parent cfce7d9 commit 438ba0d
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-taxis-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": minor
---

Add analytics for llm new account list ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Flex, Icons } from "@ledgerhq/native-ui";
import { useNavigation } from "@react-navigation/native";
import { NavigationProp, NavigationState, useNavigation } from "@react-navigation/native";
import React from "react";
import Touchable from "./Touchable";

Expand All @@ -8,7 +8,11 @@ type Props = {
* Function called when user presses on the back arrow.
* If undefined: default `navigation.goBack` is used.
*/
onPress?: () => void;
onPress?: (
nav: Omit<NavigationProp<ReactNavigation.RootParamList>, "getState"> & {
getState(): NavigationState | undefined;
},
) => void;
};

export const NavigationHeaderBackImage = () => (
Expand All @@ -25,7 +29,7 @@ export const NavigationHeaderBackButton: React.FC<Props> = React.memo(({ onPress
return (
<Touchable
testID="navigation-header-back-button"
onPress={() => (onPress ? onPress() : navigation.goBack())}
onPress={() => (onPress ? onPress(navigation) : navigation.goBack())}
>
<NavigationHeaderBackImage />
</Touchable>
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 { useSelector } from "react-redux";
Expand All @@ -25,17 +25,47 @@ import type { AccountsNavigatorParamList } from "./types/AccountsNavigator";
import { hasNoAccountsSelector } from "~/reducers/accounts";
import AccountsList from "LLM/features/Accounts/screens/AccountsList";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { NavigationHeaderBackButton } from "../NavigationHeaderBackButton";
import { track } from "~/analytics";
import { NavigationProp, NavigationState, useNavigation, useRoute } from "@react-navigation/native";
import { TrackingEvent } from "LLM/features/Accounts/enums";

const Stack = createStackNavigator<AccountsNavigatorParamList>();

type NavType = Omit<NavigationProp<ReactNavigation.RootParamList>, "getState"> & {
getState(): NavigationState | undefined;
};

type ParamsType = {
specificAccounts?: object;
};

export default function AccountsNavigator() {
const { colors } = useTheme();
const stackNavConfig = useMemo(() => getStackNavigatorConfig(colors), [colors]);
const accountListUIFF = useFeature("llmAccountListUI");
const route = useRoute();
const navigation = useNavigation();

const hasNoAccounts = useSelector(hasNoAccountsSelector);
const readOnlyModeEnabled = useSelector(readOnlyModeEnabledSelector) && hasNoAccounts;

const onPressBack = useCallback(
(nav: NavType) => {
// Needed since we use the same screen for different purposes
const params: ParamsType = navigation.getState()?.routes[1].params || {};
const screenName = params.specificAccounts
? TrackingEvent.AccountListSummary
: TrackingEvent.AccountsList;
track("button_clicked", {
button: "Back",
page: screenName || route.name,
});
nav.goBack();
},
[navigation, route.name],
);

return (
<Stack.Navigator screenOptions={stackNavConfig}>
<Stack.Screen
Expand Down Expand Up @@ -84,6 +114,7 @@ export default function AccountsNavigator() {
component={AccountsList}
options={{
headerTitle: "",
headerLeft: () => <NavigationHeaderBackButton onPress={onPressBack} />,
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from "react";
import { Platform } from "react-native";
import { createStackNavigator } from "@react-navigation/stack";
import { useTheme } from "styled-components/native";
import { useRoute } from "@react-navigation/native";
import { useNavigation, useRoute } from "@react-navigation/native";
import { ScreenName } from "~/const";
import { getStackNavigatorConfig } from "~/navigation/navigatorConfig";
import { track } from "~/analytics";
Expand All @@ -13,11 +13,13 @@ import ScanDeviceAccounts from "LLM/features/Accounts/screens/ScanDeviceAccounts
import { AccountsListNavigator } from "./screens/AccountsList/types";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import AccountsList from "LLM/features/Accounts/screens/AccountsList";
import { NavigationHeaderBackButton } from "~/components/NavigationHeaderBackButton";

export default function Navigator() {
const { colors } = useTheme();
const route = useRoute();
const accountListUIFF = useFeature("llmAccountListUI");
const navigation = useNavigation();

const onClose = useCallback(() => {
track("button_clicked", {
Expand All @@ -34,6 +36,14 @@ export default function Navigator() {
[colors, onClose],
);

const onPressBack = useCallback(() => {
track("button_clicked", {
button: "Back",
page: route.name,
});
navigation.goBack();
}, [route, navigation]);

return (
<Stack.Navigator
screenOptions={{
Expand Down Expand Up @@ -65,6 +75,7 @@ export default function Navigator() {
component={AccountsList}
options={{
headerTitle: "",
headerLeft: () => <NavigationHeaderBackButton onPress={onPressBack} />,
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ type Props = {
sourceScreenName: string;
onClick?: () => void;
disabled?: boolean;
currency?: string;
};

const AddAccountButton: React.FC<Props> = ({ sourceScreenName, disabled, onClick }) => {
const AddAccountButton: React.FC<Props> = ({ sourceScreenName, disabled, currency, onClick }) => {
const { t } = useTranslation();
const [isAddModalOpened, setAddModalOpened] = useState<boolean>(false);

const openAddModal = () => {
track("button_clicked", { button: "Add a new account", page: sourceScreenName });
track("button_clicked", { button: "Add a new account", page: sourceScreenName, currency });
if (onClick) {
onClick();
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum TrackingEvent {
AccountListSummary = "Account List Summary",
AccountsList = "Accounts",
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { useGroupedCurrenciesByProvider } from "@ledgerhq/live-common/deposit/index";
import { LoadingBasedGroupedCurrencies, LoadingStatus } from "@ledgerhq/live-common/deposit/type";
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";

import { TrackingEvent } from "../../enums";
type Props = StackNavigatorProps<AccountsListNavigator, ScreenName.AccountsList>;

export default function AccountsList({ route }: Props) {
Expand Down Expand Up @@ -103,10 +103,13 @@ export default function AccountsList({ route }: Props) {
}, [currency, llmNetworkBasedAddAccountFlow?.enabled, navigation, provider, specificAccounts]);

const onClick = specificAccounts ? onAddAccount : undefined;

const pageTrackingEvent = specificAccounts
? TrackingEvent.AccountListSummary
: TrackingEvent.AccountsList;
const currencyToTrack = specificAccounts ? currency?.name : undefined;
return (
<>
<TrackScreen event="Accounts" />
<TrackScreen name={pageTrackingEvent} source={sourceScreenName} currency={currencyToTrack} />
<ReactNavigationPerformanceView screenName={ScreenName.AccountsList} interactive>
<SafeAreaView edges={["left", "right", "bottom"]} isFlex style={{ marginHorizontal: 16 }}>
{showHeader && (
Expand All @@ -129,7 +132,8 @@ export default function AccountsList({ route }: Props) {
{canAddAccount && (
<AddAccountButton
disabled={isAddAccountCtaDisabled}
sourceScreenName="Accounts"
sourceScreenName={pageTrackingEvent}
currency={currencyToTrack}
onClick={onClick}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function AssetsList({ route }: Props) {

return (
<>
<TrackScreen event="Accounts" />
<TrackScreen event="Assets" source={sourceScreenName} />
<ReactNavigationPerformanceView screenName={ScreenName.AssetsList} interactive>
<SafeAreaView edges={["left", "right", "bottom"]} isFlex style={{ marginHorizontal: 16 }}>
{showHeader && (
Expand Down

0 comments on commit 438ba0d

Please sign in to comment.