Skip to content

Commit c93d6ac

Browse files
chore(lld): swapped string to enum for tracking locations
1 parent a1a7f2d commit c93d6ac

17 files changed

+52
-39
lines changed

.changeset/wise-frogs-kiss.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"ledger-live-desktop": minor
33
---
44

5-
Add Tracking in the ledger sync flow
5+
Add Tracking in the ledger sync flow and polish tracking implementation

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackAddAccountModal.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UseTrackAddAccountModal, useTrackAddAccountModal } from "./useTrackAddA
33
import { track } from "../segment";
44
import { CantOpenDevice, UserRefusedOnDevice, LockedDeviceError } from "@ledgerhq/errors";
55
import type { Device } from "@ledgerhq/types-devices";
6-
import { CONNECTION_TYPES } from "./variables";
6+
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";
77

88
jest.mock("../segment", () => ({
99
track: jest.fn(),
@@ -16,7 +16,7 @@ describe("useTrackAddAccountModal", () => {
1616
};
1717

1818
const defaultArgs: UseTrackAddAccountModal = {
19-
location: "Add account modal",
19+
location: HOOKS_TRACKING_LOCATIONS.addAccountModal,
2020
requestOpenApp: "Bitcoin",
2121
device: deviceMock,
2222
error: null,
@@ -43,7 +43,7 @@ describe("useTrackAddAccountModal", () => {
4343
deviceType: "europa",
4444
connectionType: CONNECTION_TYPES.BLE,
4545
platform: "LLD",
46-
page: "Add account modal",
46+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
4747
}),
4848
true,
4949
);
@@ -70,7 +70,7 @@ describe("useTrackAddAccountModal", () => {
7070
deviceType: "europa",
7171
connectionType: CONNECTION_TYPES.BLE,
7272
platform: "LLD",
73-
page: "Add account modal",
73+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
7474
}),
7575
true,
7676
);
@@ -90,7 +90,7 @@ describe("useTrackAddAccountModal", () => {
9090
deviceType: "europa",
9191
connectionType: CONNECTION_TYPES.BLE,
9292
platform: "LLD",
93-
page: "Add account modal",
93+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
9494
}),
9595
true,
9696
);
@@ -110,7 +110,7 @@ describe("useTrackAddAccountModal", () => {
110110
deviceType: "europa",
111111
connectionType: CONNECTION_TYPES.BLE,
112112
platform: "LLD",
113-
page: "Add account modal",
113+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
114114
}),
115115
true,
116116
);
@@ -130,7 +130,7 @@ describe("useTrackAddAccountModal", () => {
130130
deviceType: "europa",
131131
connectionType: CONNECTION_TYPES.BLE,
132132
platform: "LLD",
133-
page: "Add account modal",
133+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
134134
}),
135135
true,
136136
);
@@ -157,13 +157,13 @@ describe("useTrackAddAccountModal", () => {
157157
deviceType: "europa",
158158
connectionType: CONNECTION_TYPES.USB,
159159
platform: "LLD",
160-
page: "Add account modal",
160+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
161161
}),
162162
true,
163163
);
164164
});
165165

166-
it('should not track if location is not "Add account modal"', () => {
166+
it("should not track if location is not HOOKS_TRACKING_LOCATIONS.addAccountModal", () => {
167167
renderHook(() =>
168168
useTrackAddAccountModal({
169169
...defaultArgs,
@@ -191,7 +191,7 @@ describe("useTrackAddAccountModal", () => {
191191
deviceType: "europa",
192192
connectionType: CONNECTION_TYPES.USB,
193193
platform: "LLD",
194-
page: "Add account modal",
194+
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
195195
}),
196196
true,
197197
);

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackAddAccountModal.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { useRef, useEffect } from "react";
22
import { track } from "../segment";
33
import { Device } from "@ledgerhq/types-devices";
44
import { UserRefusedOnDevice, LockedDeviceError, CantOpenDevice } from "@ledgerhq/errors";
5-
import { CONNECTION_TYPES } from "./variables";
5+
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";
66
import { LedgerError } from "~/renderer/components/DeviceAction";
77

88
export type UseTrackAddAccountModal = {
9-
location: string | undefined;
9+
location: HOOKS_TRACKING_LOCATIONS.addAccountModal | undefined;
1010
device: Device;
1111
error:
1212
| (LedgerError & {
@@ -31,7 +31,7 @@ function getConnectionType(d?: Device): string | undefined {
3131
* a custom hook to track events in the Add Account Modal.
3232
* tracks user interactions with the Add Account Modal based on state changes and errors.
3333
*
34-
* @param location - current location in the app (expected "Add account modal").
34+
* @param location - current location in the app (expected "Add account modal" from HOOKS_TRACKING_LOCATIONS enum).
3535
* @param device - the connected device information.
3636
* @param error - current error state.
3737
* @param isTrackingEnabled - flag indicating if tracking is enabled.
@@ -52,7 +52,7 @@ export const useTrackAddAccountModal = ({
5252
const previousDevice = useRef<Device | null | undefined>(undefined);
5353

5454
useEffect(() => {
55-
if (location !== "Add account modal") return;
55+
if (location !== HOOKS_TRACKING_LOCATIONS.addAccountModal) return;
5656

5757
const defaultPayload = {
5858
deviceType: device?.modelId || previousDevice.current?.modelId || undefined,

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackManagerSectionEvents.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
UserRefusedDeviceNameChange,
1010
UserRefusedFirmwareUpdate,
1111
} from "@ledgerhq/errors";
12-
import { CONNECTION_TYPES } from "./variables";
12+
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";
1313

1414
jest.mock("../segment", () => ({
1515
track: jest.fn(),
@@ -23,7 +23,7 @@ describe("useTrackManagerSectionEvents", () => {
2323
};
2424

2525
const defaultArgs: UseTrackManagerSectionEvents = {
26-
location: "Manager Dashboard",
26+
location: HOOKS_TRACKING_LOCATIONS.managerDashboard,
2727
device: deviceMock,
2828
allowManagerRequested: null,
2929
clsImageRemoved: null,
@@ -51,7 +51,7 @@ describe("useTrackManagerSectionEvents", () => {
5151
deviceType: "europa",
5252
connectionType: CONNECTION_TYPES.USB,
5353
platform: "LLD",
54-
page: "Manager Dashboard",
54+
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
5555
}),
5656
true,
5757
);
@@ -75,7 +75,7 @@ describe("useTrackManagerSectionEvents", () => {
7575
deviceType: "europa",
7676
connectionType: CONNECTION_TYPES.USB,
7777
platform: "LLD",
78-
page: "Manager Dashboard",
78+
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
7979
}),
8080
true,
8181
);
@@ -94,7 +94,7 @@ describe("useTrackManagerSectionEvents", () => {
9494
deviceType: "europa",
9595
connectionType: CONNECTION_TYPES.USB,
9696
platform: "LLD",
97-
page: "Manager Dashboard",
97+
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
9898
}),
9999
true,
100100
);
@@ -113,7 +113,7 @@ describe("useTrackManagerSectionEvents", () => {
113113
deviceType: "europa",
114114
connectionType: CONNECTION_TYPES.USB,
115115
platform: "LLD",
116-
page: "Manager Dashboard",
116+
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
117117
}),
118118
true,
119119
);
@@ -132,7 +132,7 @@ describe("useTrackManagerSectionEvents", () => {
132132
deviceType: "europa",
133133
connectionType: CONNECTION_TYPES.USB,
134134
platform: "LLD",
135-
page: "Manager Dashboard",
135+
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
136136
}),
137137
true,
138138
);

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackManagerSectionEvents.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
} from "@ledgerhq/errors";
77
import { track } from "../segment";
88
import { Device } from "@ledgerhq/types-devices";
9-
import { CONNECTION_TYPES } from "./variables";
9+
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";
1010
import { LedgerError } from "~/renderer/components/DeviceAction";
1111

1212
export type UseTrackManagerSectionEvents = {
13-
location: string | undefined;
13+
location: HOOKS_TRACKING_LOCATIONS.managerDashboard | undefined;
1414
device: Device;
1515
allowManagerRequested: boolean | null | undefined;
1616
error:
@@ -28,7 +28,7 @@ export type UseTrackManagerSectionEvents = {
2828
* a custom hook to track events in the Manager section.
2929
* tracks user interactions with the Manager dashboard based on state changes and errors.
3030
*
31-
* @param location - current location in the app (expected "Manager").
31+
* @param location - current location in the app (expected "Manager Dashboard" from HOOKS_TRACKING_LOCATIONS enum).
3232
* @param device - the connected device information.
3333
* @param allowManagerRequested - flag indicating if the user has allowed the Manager app.
3434
* @param clsImageRemoved - flag indicating if the user has removed the custom lock screen image.
@@ -47,7 +47,7 @@ export const useTrackManagerSectionEvents = ({
4747
const previousAllowManagerRequested = useRef<boolean | null | undefined>(undefined);
4848

4949
useEffect(() => {
50-
if (location !== "Manager Dashboard") return;
50+
if (location !== HOOKS_TRACKING_LOCATIONS.managerDashboard) return;
5151

5252
const defaultPayload = {
5353
deviceType: device?.modelId,

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackReceiveFlow.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { renderHook } from "tests/testUtils";
22
import { useTrackReceiveFlow, UseTrackReceiveFlow } from "./useTrackReceiveFlow";
33
import { track } from "../segment";
44
import { UserRefusedOnDevice } from "@ledgerhq/errors";
5+
import { HOOKS_TRACKING_LOCATIONS } from "./variables";
56

67
jest.mock("../segment", () => ({
78
track: jest.fn(),
@@ -15,7 +16,7 @@ describe("useTrackReceiveFlow", () => {
1516
};
1617

1718
const defaultArgs: UseTrackReceiveFlow = {
18-
location: "Receive Modal",
19+
location: HOOKS_TRACKING_LOCATIONS.receiveModal,
1920
device: deviceMock,
2021
verifyAddressError: null,
2122
error: null,

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackReceiveFlow.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { track } from "../segment";
33
import { Device } from "@ledgerhq/types-devices";
44
import { UserRefusedOnDevice } from "@ledgerhq/errors";
55
import { LedgerError } from "~/renderer/components/DeviceAction";
6+
import { HOOKS_TRACKING_LOCATIONS } from "./variables";
67

78
export type UseTrackReceiveFlow = {
8-
location: string | undefined;
9+
location: HOOKS_TRACKING_LOCATIONS.receiveModal | undefined;
910
device: Device;
1011
verifyAddressError?:
1112
| {
@@ -33,7 +34,7 @@ export type UseTrackReceiveFlow = {
3334
* a custom hook to track events in the Receive modal.
3435
* tracks user interactions with the Receive modal based on state changes and errors.
3536
*
36-
* @param location - current location in the app (expected "Receive Modal").
37+
* @param location - current location in the app (expected "Receive Modal" from HOOKS_TRACKING_LOCATIONS enum).
3738
* @param device - the connected device information.
3839
* @param verifyAddressError - optional - error from verifying address.
3940
* @param error - optional - current error state.
@@ -49,7 +50,7 @@ export const useTrackReceiveFlow = ({
4950
isTrackingEnabled,
5051
}: UseTrackReceiveFlow) => {
5152
useEffect(() => {
52-
if (location !== "Receive Modal") return;
53+
if (location !== HOOKS_TRACKING_LOCATIONS.receiveModal) return;
5354

5455
const defaultPayload = {
5556
deviceType: device?.modelId,

apps/ledger-live-desktop/src/renderer/analytics/hooks/useTrackSyncFlow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { HOOKS_TRACKING_LOCATIONS } from "./variables";
88
type LedgerError = InstanceType<LedgerErrorConstructor<{ [key: string]: unknown }>>;
99

1010
export type UseTrackSyncFlow = {
11-
location: string | undefined;
11+
location: HOOKS_TRACKING_LOCATIONS.ledgerSync | undefined;
1212
device: Device;
1313
allowManagerRequested: boolean | null | undefined;
1414
error?:

apps/ledger-live-desktop/src/renderer/analytics/hooks/variables.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ export enum CONNECTION_TYPES {
55

66
export enum HOOKS_TRACKING_LOCATIONS {
77
ledgerSync = "Ledger Sync",
8+
addAccountModal = "Add account modal",
9+
managerDashboard = "Manager Dashboard",
10+
receiveModal = "Receive Modal",
811
}

apps/ledger-live-desktop/src/renderer/components/DeviceAction/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import { useTrackManagerSectionEvents } from "~/renderer/analytics/hooks/useTrac
8484
import { useTrackReceiveFlow } from "~/renderer/analytics/hooks/useTrackReceiveFlow";
8585
import { useTrackAddAccountModal } from "~/renderer/analytics/hooks/useTrackAddAccountModal";
8686
import { useTrackSyncFlow } from "~/renderer/analytics/hooks/useTrackSyncFlow";
87+
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
8788

8889
export type LedgerError = InstanceType<LedgerErrorConstructor<{ [key: string]: unknown }>>;
8990

@@ -160,7 +161,7 @@ type InnerProps<P> = {
160161
analyticsPropertyFlow?: string;
161162
overridesPreferredDeviceModel?: DeviceModelId;
162163
inlineRetry?: boolean; // Set to false if the retry mechanism is handled externally.
163-
location?: string;
164+
location?: HOOKS_TRACKING_LOCATIONS;
164165
};
165166

166167
type Props<H extends States, P> = InnerProps<P> & {

apps/ledger-live-desktop/src/renderer/components/Stepper/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useSelector } from "react-redux";
1010
import { trackingEnabledSelector } from "~/renderer/reducers/settings";
1111
import { getCurrentDevice } from "~/renderer/reducers/devices";
1212
import { LedgerError } from "../DeviceAction";
13+
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
1314

1415
export type BasicStepProps = {
1516
t: TFunction;
@@ -72,7 +73,7 @@ const Stepper = <T, StepProps>({
7273
[onStepChange, steps],
7374
);
7475
useTrackAddAccountModal({
75-
location: "Add account modal",
76+
location: HOOKS_TRACKING_LOCATIONS.addAccountModal,
7677
device: useSelector(getCurrentDevice),
7778
error: err,
7879
isTrackingEnabled: useSelector(trackingEnabledSelector),

apps/ledger-live-desktop/src/renderer/modals/AddAccounts/steps/StepConnectDevice.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { StepProps } from "..";
88
import { getEnv } from "@ledgerhq/live-env";
99
import { mockedEventEmitter } from "~/renderer/components/debug/DebugMock";
1010
import connectApp from "@ledgerhq/live-common/hw/connectApp";
11+
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
1112
const action = createAction(getEnv("MOCK") ? mockedEventEmitter : connectApp);
1213
const StepConnectDevice = ({ currency, transitionTo, flow }: StepProps) => {
1314
invariant(currency, "No crypto asset given");
@@ -40,7 +41,7 @@ const StepConnectDevice = ({ currency, transitionTo, flow }: StepProps) => {
4041
transitionTo("import");
4142
}}
4243
analyticsPropertyFlow={flow}
43-
location="Add account modal"
44+
location={HOOKS_TRACKING_LOCATIONS.addAccountModal}
4445
/>
4546
</>
4647
);

apps/ledger-live-desktop/src/renderer/modals/Receive/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { openModal, closeModal } from "~/renderer/actions/modals";
88
import { useTrackReceiveFlow } from "~/renderer/analytics/hooks/useTrackReceiveFlow";
99
import { trackingEnabledSelector } from "~/renderer/reducers/settings";
1010
import { getCurrentDevice } from "~/renderer/reducers/devices";
11+
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
1112

1213
type State = {
1314
stepId: StepId;
@@ -28,7 +29,7 @@ const ReceiveModal = () => {
2829
const device = useSelector(getCurrentDevice);
2930

3031
useTrackReceiveFlow({
31-
location: "Receive Modal",
32+
location: HOOKS_TRACKING_LOCATIONS.receiveModal,
3233
device,
3334
verifyAddressError,
3435
isTrackingEnabled: useSelector(trackingEnabledSelector),

apps/ledger-live-desktop/src/renderer/modals/Receive/steps/StepConnectDevice.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import connectApp from "@ledgerhq/live-common/hw/connectApp";
1010
import { StepProps } from "../Body";
1111
import { mockedEventEmitter } from "~/renderer/components/debug/DebugMock";
1212
import { getEnv } from "@ledgerhq/live-env";
13+
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
1314
const action = createAction(getEnv("MOCK") ? mockedEventEmitter : connectApp);
1415
export default function StepConnectDevice({
1516
account,
@@ -34,7 +35,7 @@ export default function StepConnectDevice({
3435
request={request}
3536
onResult={() => transitionTo("receive")}
3637
analyticsPropertyFlow="receive"
37-
location="Receive Modal"
38+
location={HOOKS_TRACKING_LOCATIONS.receiveModal}
3839
/>
3940
</>
4041
);

apps/ledger-live-desktop/src/renderer/screens/manager/DeviceDashboard/DeviceInformationSummary/EditDeviceName.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import getDeviceNameMaxLength from "@ledgerhq/live-common/hw/getDeviceNameMaxLen
1313
import renameDevice from "@ledgerhq/live-common/hw/renameDevice";
1414
import { withV3StyleProvider } from "~/renderer/styles/StyleProviderV3";
1515
import { DeviceInfo } from "@ledgerhq/types-live";
16+
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
1617

1718
const action = createAction(renameDevice);
1819

@@ -144,7 +145,7 @@ const EditDeviceName: React.FC<Props> = ({
144145
inlineRetry={false}
145146
onResult={onSuccess}
146147
onError={(error: Error) => setActionError(error)}
147-
location="Manager Dashboard"
148+
location={HOOKS_TRACKING_LOCATIONS.managerDashboard}
148149
/>
149150
</Flex>
150151
) : (

0 commit comments

Comments
 (0)