diff --git a/.changeset/thin-planets-accept.md b/.changeset/thin-planets-accept.md new file mode 100644 index 000000000000..55789124f459 --- /dev/null +++ b/.changeset/thin-planets-accept.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": minor +--- + +Add swap related analytic events diff --git a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx index a03755344b9a..157327bec91b 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/FeesDrawerLiveApp/index.tsx @@ -13,6 +13,7 @@ import { getMainAccount } from "@ledgerhq/live-common/account/index"; import LowGasAlertBuyMore from "~/renderer/families/evm/SendAmountFields/LowGasAlertBuyMore"; import TranslatedError from "~/renderer/components/TranslatedError"; import Alert from "~/renderer/components/Alert"; +import { useTrack } from "~/renderer/analytics/segment"; type Props = { setTransaction: SwapTransactionType["setTransaction"]; @@ -36,6 +37,7 @@ export default function FeesDrawerLiveApp({ disableSlowStrategy = false, }: Props) { const swapDefaultTrack = useGetSwapTrackingProperties(); + const track = useTrack(); const [isOpen, setIsOpen] = useState(true); const [transaction, setTransactionState] = useState(initialTransaction); @@ -67,6 +69,15 @@ export default function FeesDrawerLiveApp({ (updater: (arg0: Transaction) => Transaction) => { setTransactionState(prevTransaction => { let updatedTransaction = updater(prevTransaction); + + if (prevTransaction.feesStrategy !== updatedTransaction.feesStrategy) { + track("button_clicked", { + ...swapDefaultTrack, + button: updatedTransaction.feesStrategy, + page: "quoteSwap", + }); + } + bridge .prepareTransaction(mainAccount, updatedTransaction) .then(preparedTransaction => @@ -84,7 +95,7 @@ export default function FeesDrawerLiveApp({ return updatedTransaction; }); }, - [setTransaction, bridge, mainAccount], + [setTransaction, bridge, mainAccount, swapDefaultTrack, track], ); const mapStrategies = useCallback( diff --git a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Navbar/index.tsx b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Navbar/index.tsx index 8ed2a77d40f9..3f0ea2c5cd82 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Navbar/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Navbar/index.tsx @@ -37,8 +37,8 @@ const Navbar = () => { ); const onWrappedTabChange = (nextIndex: number) => { - track("button_clicked2", { - button: `${swapRoutes[nextIndex].name} Tab`, + track("button_clicked", { + button: `${swapRoutes[nextIndex].name}`, page: "Page Swap Form", ...swapDefaultTrack, }); diff --git a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/utils/index.ts b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/utils/index.ts index 2cf92502a3ae..9ccdec5f376e 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/utils/index.ts +++ b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/utils/index.ts @@ -10,6 +10,7 @@ export const SWAP_VERSION = "2.35"; const SWAP_TRACKING_PROPERTIES = { swapVersion: SWAP_VERSION, flow: "swap", + live_app: "swap", }; export const useGetSwapTrackingProperties = () => { diff --git a/apps/ledger-live-desktop/src/renderer/screens/platform/LiveApp.tsx b/apps/ledger-live-desktop/src/renderer/screens/platform/LiveApp.tsx index 7ab5bfe641cc..46e8b0714cea 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/platform/LiveApp.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/platform/LiveApp.tsx @@ -7,6 +7,8 @@ import { languageSelector } from "~/renderer/reducers/settings"; import { useSelector } from "react-redux"; import { useRemoteLiveAppManifest } from "@ledgerhq/live-common/platform/providers/RemoteLiveAppProvider/index"; import { useLocalLiveAppManifest } from "@ledgerhq/live-common/wallet-api/LocalLiveAppProvider/index"; +import { useTrack } from "~/renderer/analytics/segment"; +import { useGetSwapTrackingProperties } from "../exchange/Swap2/utils"; type Props = { match: { @@ -31,6 +33,8 @@ type Props = { export function LiveApp({ match, appId: propsAppId, location }: Props) { const history = useHistory(); + const track = useTrack(); + const swapTrackingProperties = useGetSwapTrackingProperties(); const { params: internalParams, search } = location; const { state: urlParams, customDappUrl } = useLocation() as ReturnType & Props["location"] & { @@ -55,7 +59,17 @@ export function LiveApp({ match, appId: propsAppId, location }: Props) { ); }, [search, customDappUrl, urlParams?.customDappUrl, internalParams?.customDappUrl]); - const handleClose = useCallback(() => history.push(returnTo || `/platform`), [history, returnTo]); + const handleClose = useCallback(() => { + if (returnTo.startsWith("/swap")) { + track("button_click", { + ...swapTrackingProperties, + button: "close X", + partner: appId, + page: "swap", + }); + } + history.push(returnTo || `/platform`); + }, [history, returnTo, appId, swapTrackingProperties, track]); const themeType = useTheme().colors.palette.type; const lang = useSelector(languageSelector); const params = {