From 4cd70ed743fadf07545a7e45396d93126cb40d15 Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Fri, 8 Nov 2024 09:49:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8D=20feat(lld):=20track=20Ledger=20ke?= =?UTF-8?q?yring=20activation/deactivation=20on=20LLM=20(#8320)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(llm): track "ledgersync_activated" events * feat(llm): track "ledgersync_deactivated" events * fix(llm): track the events without the function from "~/analytics" * chore: update change log * chore(llm): move the tracking events strings in an enum * chore(llm): rename Analytics/constants to Analytics/enums --- .changeset/two-seas-push.md | 5 +++++ .../src/newArch/features/Analytics/enums.ts | 4 ++++ .../src/newArch/features/WalletSync/hooks/useAddMember.ts | 3 +++ .../features/WalletSync/hooks/useDestroyTrustchain.ts | 3 +++ .../WalletSync/hooks/useOnTrustchainRefreshNeeded.ts | 3 +++ .../src/newArch/features/WalletSync/hooks/useQRCodeHost.ts | 3 +++ .../newArch/features/WalletSync/hooks/useSyncWithQrCode.ts | 3 +++ .../newArch/features/WalletSync/hooks/walletSync.hooks.ts | 3 +++ 8 files changed, 27 insertions(+) create mode 100644 .changeset/two-seas-push.md create mode 100644 apps/ledger-live-mobile/src/newArch/features/Analytics/enums.ts diff --git a/.changeset/two-seas-push.md b/.changeset/two-seas-push.md new file mode 100644 index 000000000000..6a457ea7093d --- /dev/null +++ b/.changeset/two-seas-push.md @@ -0,0 +1,5 @@ +--- +"live-mobile": minor +--- + +Track users creating, joining, and leaving Ledger keyrings on LLM diff --git a/apps/ledger-live-mobile/src/newArch/features/Analytics/enums.ts b/apps/ledger-live-mobile/src/newArch/features/Analytics/enums.ts new file mode 100644 index 000000000000..7ca2a5d87d86 --- /dev/null +++ b/apps/ledger-live-mobile/src/newArch/features/Analytics/enums.ts @@ -0,0 +1,4 @@ +export enum AnalyticsEvents { + LedgerSyncActivated = "ledgersync_activated", + LedgerSyncDeactivated = "ledgersync_deactivated", +} diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useAddMember.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useAddMember.ts index a54d98f44ec5..76d1da9ca747 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useAddMember.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useAddMember.ts @@ -15,6 +15,8 @@ import { TrustchainResult, TrustchainResultType } from "@ledgerhq/ledger-key-rin import { useCallback, useRef } from "react"; import { Device } from "@ledgerhq/live-common/hw/actions/types"; import { useNavigation } from "@react-navigation/native"; +import { AnalyticsEvents } from "~/newArch/features/Analytics/enums"; +import { track } from "~/analytics"; import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator"; import { StackNavigatorNavigation } from "~/components/RootNavigator/types/helpers"; import { ScreenName } from "~/const"; @@ -34,6 +36,7 @@ export function useAddMember({ device }: { device: Device | null }): DrawerProps const transitionToNextScreen = useCallback( (trustchainResult: TrustchainResult) => { dispatch(setTrustchain(trustchainResult.trustchain)); + track(AnalyticsEvents.LedgerSyncActivated); navigation.navigate(ScreenName.WalletSyncLoading, { created: trustchainResult.type === TrustchainResultType.created, }); diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useDestroyTrustchain.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useDestroyTrustchain.ts index 80b53c2e6296..032eb3eae0cc 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useDestroyTrustchain.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useDestroyTrustchain.ts @@ -6,6 +6,8 @@ import { memberCredentialsSelector, } from "@ledgerhq/ledger-key-ring-protocol/store"; import { useMutation } from "@tanstack/react-query"; +import { AnalyticsEvents } from "~/newArch/features/Analytics/enums"; +import { track } from "~/analytics"; import { QueryKey } from "./type.hooks"; import { useCloudSyncSDK } from "./useWatchWalletSync"; import { walletSyncUpdate } from "@ledgerhq/live-wallet/store"; @@ -31,6 +33,7 @@ export function useDestroyTrustchain() { mutationKey: [QueryKey.destroyTrustchain, trustchain], onSuccess: () => { dispatch(resetTrustchainStore()); + track(AnalyticsEvents.LedgerSyncDeactivated); dispatch(walletSyncUpdate(null, 0)); setCurrentStep(Steps.Activation); }, diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useOnTrustchainRefreshNeeded.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useOnTrustchainRefreshNeeded.ts index a02dfd3c052e..a6004762cdf1 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useOnTrustchainRefreshNeeded.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useOnTrustchainRefreshNeeded.ts @@ -8,6 +8,8 @@ import { import { setTrustchain, resetTrustchainStore } from "@ledgerhq/ledger-key-ring-protocol/store"; import { TrustchainEjected } from "@ledgerhq/ledger-key-ring-protocol/errors"; import { log } from "@ledgerhq/logs"; +import { AnalyticsEvents } from "~/newArch/features/Analytics/enums"; +import { track } from "~/analytics"; export function useOnTrustchainRefreshNeeded( trustchainSdk: TrustchainSDK, @@ -24,6 +26,7 @@ export function useOnTrustchainRefreshNeeded( } catch (e) { if (e instanceof TrustchainEjected) { dispatch(resetTrustchainStore()); + track(AnalyticsEvents.LedgerSyncDeactivated); } } }, diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts index afa3c184ab3b..c331e8798536 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useQRCodeHost.ts @@ -12,6 +12,8 @@ import { memberCredentialsSelector, setTrustchain, } from "@ledgerhq/ledger-key-ring-protocol/store"; +import { AnalyticsEvents } from "~/newArch/features/Analytics/enums"; +import { track } from "~/analytics"; import { useTrustchainSdk } from "./useTrustchainSdk"; import { Options, Steps } from "../types/Activation"; import { useNavigation } from "@react-navigation/native"; @@ -74,6 +76,7 @@ export function useQRCodeHost({ currentOption }: Props) { onSuccess: newTrustchain => { if (newTrustchain) { dispatch(setTrustchain(newTrustchain)); + if (!trustchain) track(AnalyticsEvents.LedgerSyncActivated); } queryClient.invalidateQueries({ queryKey: [QueryKey.getMembers] }); navigation.navigate(NavigatorName.WalletSync, { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts index d5fe6bd0ca1e..cc55141464cd 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts @@ -12,6 +12,8 @@ import { import { setTrustchain, trustchainSelector } from "@ledgerhq/ledger-key-ring-protocol/store"; import { useDispatch, useSelector } from "react-redux"; import { useNavigation } from "@react-navigation/native"; +import { AnalyticsEvents } from "~/newArch/features/Analytics/enums"; +import { track } from "~/analytics"; import { Steps } from "../types/Activation"; import { NavigatorName, ScreenName } from "~/const"; import { useInstanceName } from "./useInstanceName"; @@ -70,6 +72,7 @@ export const useSyncWithQrCode = () => { }); if (newTrustchain) { dispatch(setTrustchain(newTrustchain)); + if (!trustchain) track(AnalyticsEvents.LedgerSyncActivated); } onSyncFinished(); return true; diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts index 7758591821c8..f9f0dd7829a2 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts @@ -7,6 +7,8 @@ import { } from "@ledgerhq/ledger-key-ring-protocol/errors"; import { ErrorType } from "./type.hooks"; import { StackActions, useNavigation } from "@react-navigation/native"; +import { AnalyticsEvents } from "~/newArch/features/Analytics/enums"; +import { track } from "~/analytics"; import { useTrustchainSdk } from "./useTrustchainSdk"; import { useRestoreTrustchain } from "./useRestoreTrustchain"; import { NavigatorName, ScreenName } from "~/const"; @@ -19,6 +21,7 @@ export const useLifeCycle = () => { function reset() { dispatch(resetTrustchainStore()); + track(AnalyticsEvents.LedgerSyncDeactivated); const routeName = NavigatorName.WalletSync; const screen = ScreenName.WalletSyncActivationInit; navigation.dispatch(StackActions.replace(routeName, { screen }));