Skip to content

Commit

Permalink
chore(lld): swapped string to enum for tracking locations
Browse files Browse the repository at this point in the history
  • Loading branch information
fAnselmi-Ledger committed Feb 7, 2025
1 parent a1a7f2d commit e1f5b99
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .changeset/wise-frogs-kiss.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"ledger-live-desktop": minor
---

Add Tracking in the ledger sync flow
Add Tracking in the ledger sync flow and polish tracking implementation
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UseTrackAddAccountModal, useTrackAddAccountModal } from "./useTrackAddA
import { track } from "../segment";
import { CantOpenDevice, UserRefusedOnDevice, LockedDeviceError } from "@ledgerhq/errors";
import type { Device } from "@ledgerhq/types-devices";
import { CONNECTION_TYPES } from "./variables";
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";

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

const defaultArgs: UseTrackAddAccountModal = {
location: "Add account modal",
location: HOOKS_TRACKING_LOCATIONS.addAccountModal,
requestOpenApp: "Bitcoin",
device: deviceMock,
error: null,
Expand All @@ -43,7 +43,7 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.BLE,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
Expand All @@ -70,7 +70,7 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.BLE,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
Expand All @@ -90,7 +90,7 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.BLE,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
Expand All @@ -110,7 +110,7 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.BLE,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
Expand All @@ -130,7 +130,7 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.BLE,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
Expand All @@ -157,13 +157,13 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
});

it('should not track if location is not "Add account modal"', () => {
it("should not track if location is not HOOKS_TRACKING_LOCATIONS.addAccountModal", () => {
renderHook(() =>
useTrackAddAccountModal({
...defaultArgs,
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("useTrackAddAccountModal", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Add account modal",
page: HOOKS_TRACKING_LOCATIONS.addAccountModal,
}),
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useRef, useEffect } from "react";
import { track } from "../segment";
import { Device } from "@ledgerhq/types-devices";
import { UserRefusedOnDevice, LockedDeviceError, CantOpenDevice } from "@ledgerhq/errors";
import { CONNECTION_TYPES } from "./variables";
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";
import { LedgerError } from "~/renderer/components/DeviceAction";

export type UseTrackAddAccountModal = {
Expand Down Expand Up @@ -31,7 +31,7 @@ function getConnectionType(d?: Device): string | undefined {
* a custom hook to track events in the Add Account Modal.
* tracks user interactions with the Add Account Modal based on state changes and errors.
*
* @param location - current location in the app (expected "Add account modal").
* @param location - current location in the app (expected "Add account modal" from HOOKS_TRACKING_LOCATIONS enum).
* @param device - the connected device information.
* @param error - current error state.
* @param isTrackingEnabled - flag indicating if tracking is enabled.
Expand All @@ -52,7 +52,7 @@ export const useTrackAddAccountModal = ({
const previousDevice = useRef<Device | null | undefined>(undefined);

useEffect(() => {
if (location !== "Add account modal") return;
if (location !== HOOKS_TRACKING_LOCATIONS.addAccountModal) return;

const defaultPayload = {
deviceType: device?.modelId || previousDevice.current?.modelId || undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
UserRefusedDeviceNameChange,
UserRefusedFirmwareUpdate,
} from "@ledgerhq/errors";
import { CONNECTION_TYPES } from "./variables";
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";

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

const defaultArgs: UseTrackManagerSectionEvents = {
location: "Manager Dashboard",
location: HOOKS_TRACKING_LOCATIONS.managerDashboard,
device: deviceMock,
allowManagerRequested: null,
clsImageRemoved: null,
Expand Down Expand Up @@ -51,7 +51,7 @@ describe("useTrackManagerSectionEvents", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Manager Dashboard",
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
}),
true,
);
Expand All @@ -75,7 +75,7 @@ describe("useTrackManagerSectionEvents", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Manager Dashboard",
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
}),
true,
);
Expand All @@ -94,7 +94,7 @@ describe("useTrackManagerSectionEvents", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Manager Dashboard",
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
}),
true,
);
Expand All @@ -113,7 +113,7 @@ describe("useTrackManagerSectionEvents", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Manager Dashboard",
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
}),
true,
);
Expand All @@ -132,7 +132,7 @@ describe("useTrackManagerSectionEvents", () => {
deviceType: "europa",
connectionType: CONNECTION_TYPES.USB,
platform: "LLD",
page: "Manager Dashboard",
page: HOOKS_TRACKING_LOCATIONS.managerDashboard,
}),
true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "@ledgerhq/errors";
import { track } from "../segment";
import { Device } from "@ledgerhq/types-devices";
import { CONNECTION_TYPES } from "./variables";
import { CONNECTION_TYPES, HOOKS_TRACKING_LOCATIONS } from "./variables";
import { LedgerError } from "~/renderer/components/DeviceAction";

export type UseTrackManagerSectionEvents = {
Expand All @@ -28,7 +28,7 @@ export type UseTrackManagerSectionEvents = {
* a custom hook to track events in the Manager section.
* tracks user interactions with the Manager dashboard based on state changes and errors.
*
* @param location - current location in the app (expected "Manager").
* @param location - current location in the app (expected "Manager Dashboard" from HOOKS_TRACKING_LOCATIONS enum).
* @param device - the connected device information.
* @param allowManagerRequested - flag indicating if the user has allowed the Manager app.
* @param clsImageRemoved - flag indicating if the user has removed the custom lock screen image.
Expand All @@ -47,7 +47,7 @@ export const useTrackManagerSectionEvents = ({
const previousAllowManagerRequested = useRef<boolean | null | undefined>(undefined);

useEffect(() => {
if (location !== "Manager Dashboard") return;
if (location !== HOOKS_TRACKING_LOCATIONS.managerDashboard) return;

const defaultPayload = {
deviceType: device?.modelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { renderHook } from "tests/testUtils";
import { useTrackReceiveFlow, UseTrackReceiveFlow } from "./useTrackReceiveFlow";
import { track } from "../segment";
import { UserRefusedOnDevice } from "@ledgerhq/errors";
import { HOOKS_TRACKING_LOCATIONS } from "./variables";

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

const defaultArgs: UseTrackReceiveFlow = {
location: "Receive Modal",
location: HOOKS_TRACKING_LOCATIONS.receiveModal,
device: deviceMock,
verifyAddressError: null,
error: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { track } from "../segment";
import { Device } from "@ledgerhq/types-devices";
import { UserRefusedOnDevice } from "@ledgerhq/errors";
import { LedgerError } from "~/renderer/components/DeviceAction";
import { HOOKS_TRACKING_LOCATIONS } from "./variables";

export type UseTrackReceiveFlow = {
location: string | undefined;
Expand Down Expand Up @@ -33,7 +34,7 @@ export type UseTrackReceiveFlow = {
* a custom hook to track events in the Receive modal.
* tracks user interactions with the Receive modal based on state changes and errors.
*
* @param location - current location in the app (expected "Receive Modal").
* @param location - current location in the app (expected "Receive Modal" from HOOKS_TRACKING_LOCATIONS enum).
* @param device - the connected device information.
* @param verifyAddressError - optional - error from verifying address.
* @param error - optional - current error state.
Expand All @@ -49,7 +50,7 @@ export const useTrackReceiveFlow = ({
isTrackingEnabled,
}: UseTrackReceiveFlow) => {
useEffect(() => {
if (location !== "Receive Modal") return;
if (location !== HOOKS_TRACKING_LOCATIONS.receiveModal) return;

const defaultPayload = {
deviceType: device?.modelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ export enum CONNECTION_TYPES {

export enum HOOKS_TRACKING_LOCATIONS {
ledgerSync = "Ledger Sync",
addAccountModal = "Add account modal",
managerDashboard = "Manager Dashboard",
receiveModal = "Receive Modal",
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useSelector } from "react-redux";
import { trackingEnabledSelector } from "~/renderer/reducers/settings";
import { getCurrentDevice } from "~/renderer/reducers/devices";
import { LedgerError } from "../DeviceAction";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";

export type BasicStepProps = {
t: TFunction;
Expand Down Expand Up @@ -72,7 +73,7 @@ const Stepper = <T, StepProps>({
[onStepChange, steps],
);
useTrackAddAccountModal({
location: "Add account modal",
location: HOOKS_TRACKING_LOCATIONS.addAccountModal,
device: useSelector(getCurrentDevice),
error: err,
isTrackingEnabled: useSelector(trackingEnabledSelector),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StepProps } from "..";
import { getEnv } from "@ledgerhq/live-env";
import { mockedEventEmitter } from "~/renderer/components/debug/DebugMock";
import connectApp from "@ledgerhq/live-common/hw/connectApp";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
const action = createAction(getEnv("MOCK") ? mockedEventEmitter : connectApp);
const StepConnectDevice = ({ currency, transitionTo, flow }: StepProps) => {
invariant(currency, "No crypto asset given");
Expand Down Expand Up @@ -40,7 +41,7 @@ const StepConnectDevice = ({ currency, transitionTo, flow }: StepProps) => {
transitionTo("import");
}}
analyticsPropertyFlow={flow}
location="Add account modal"
location={HOOKS_TRACKING_LOCATIONS.addAccountModal}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { openModal, closeModal } from "~/renderer/actions/modals";
import { useTrackReceiveFlow } from "~/renderer/analytics/hooks/useTrackReceiveFlow";
import { trackingEnabledSelector } from "~/renderer/reducers/settings";
import { getCurrentDevice } from "~/renderer/reducers/devices";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";

type State = {
stepId: StepId;
Expand All @@ -28,7 +29,7 @@ const ReceiveModal = () => {
const device = useSelector(getCurrentDevice);

useTrackReceiveFlow({
location: "Receive Modal",
location: HOOKS_TRACKING_LOCATIONS.receiveModal,
device,
verifyAddressError,
isTrackingEnabled: useSelector(trackingEnabledSelector),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import connectApp from "@ledgerhq/live-common/hw/connectApp";
import { StepProps } from "../Body";
import { mockedEventEmitter } from "~/renderer/components/debug/DebugMock";
import { getEnv } from "@ledgerhq/live-env";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";
const action = createAction(getEnv("MOCK") ? mockedEventEmitter : connectApp);
export default function StepConnectDevice({
account,
Expand All @@ -34,7 +35,7 @@ export default function StepConnectDevice({
request={request}
onResult={() => transitionTo("receive")}
analyticsPropertyFlow="receive"
location="Receive Modal"
location={HOOKS_TRACKING_LOCATIONS.receiveModal}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import getDeviceNameMaxLength from "@ledgerhq/live-common/hw/getDeviceNameMaxLen
import renameDevice from "@ledgerhq/live-common/hw/renameDevice";
import { withV3StyleProvider } from "~/renderer/styles/StyleProviderV3";
import { DeviceInfo } from "@ledgerhq/types-live";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";

const action = createAction(renameDevice);

Expand Down Expand Up @@ -144,7 +145,7 @@ const EditDeviceName: React.FC<Props> = ({
inlineRetry={false}
onResult={onSuccess}
onError={(error: Error) => setActionError(error)}
location="Manager Dashboard"
location={HOOKS_TRACKING_LOCATIONS.managerDashboard}
/>
</Flex>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import styled from "styled-components";
import { useTranslation } from "react-i18next";
import { clearLastSeenCustomImage } from "~/renderer/actions/settings";
import { ImageDoesNotExistOnDevice } from "@ledgerhq/live-common/errors";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";

const action = createAction(removeImage);

Expand Down Expand Up @@ -101,7 +102,7 @@ const RemoveCustomImage: React.FC<Props> = ({ onClose, onRemoved }) => {
action={action}
onResult={onSuccess}
onError={onError}
location="Manager Dashboard"
location={HOOKS_TRACKING_LOCATIONS.managerDashboard}
/>
</Flex>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useDispatch } from "react-redux";
import { context } from "~/renderer/drawers/Provider";
import { useDeviceSessionRefresherToggle } from "@ledgerhq/live-dmk";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { HOOKS_TRACKING_LOCATIONS } from "~/renderer/analytics/hooks/variables";

const action = createAction(getEnv("MOCK") ? mockedEventEmitter : connectManager);
const Manager = () => {
Expand Down Expand Up @@ -73,7 +74,7 @@ const Manager = () => {
onResult={onResult}
action={action}
request={null}
location="Manager Dashboard"
location={HOOKS_TRACKING_LOCATIONS.managerDashboard}
/>
) : (
<Disconnected onTryAgain={setHasReset} />
Expand Down

0 comments on commit e1f5b99

Please sign in to comment.