Skip to content

Commit

Permalink
fix(LIVE-14854): add swap analytics (#8416)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution! 👍
Please make sure to read CONTRIBUTING.md if you have not already. Pull Requests that do not comply with the rules will be arbitrarily closed.
-->

### ✅ Checklist

<!-- Pull Requests must pass the CI and be code reviewed. Set as Draft if the PR is not ready. -->

- [x] `npx changeset` was attached.
- [ ] **Covered by automatic tests.** <!-- if not, please explain. (Feature must be tested / Bug fix must bring non-regression) -->
- [ ] **Impact of the changes:** <!-- Please take some time to list the impact & what specific areas Quality Assurance (QA) should focus on -->
  - ...

### 📝 Description

Add analytics related to the Swap application

<!--
| Before        | After         |
| ------------- | ------------- |
|               |               |
-->

### ❓ Context

- [fix(LIVE-14877): user clicks on History tab](https://ledgerhq.atlassian.net/browse/LIVE-14877)
- [fix(LIVE-14876): user clicks on slow/medium/fast to chose network fees](https://ledgerhq.atlassian.net/browse/LIVE-14876)
- [fix(LIVE-14875): user close "X"](https://ledgerhq.atlassian.net/browse/LIVE-14875)

---

### 🧐 Checklist for the PR Reviewers

<!-- Please do not edit this if you are the PR author -->

- **The code aligns with the requirements** described in the linked JIRA or GitHub issue.
- **The PR description clearly documents the changes** made and explains any technical trade-offs or design decisions.
- **There are no undocumented trade-offs**, technical debt, or maintainability issues.
- **The PR has been tested** thoroughly, and any potential edge cases have been considered and handled.
- **Any new dependencies** have been justified and documented.
- **Performance** considerations have been taken into account. (changes have been profiled or benchmarked if necessary)
  • Loading branch information
Couto authored Nov 22, 2024
1 parent 673eae9 commit a541e82
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-planets-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

Add swap related analytic events
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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);
Expand Down Expand Up @@ -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 =>
Expand All @@ -84,7 +95,7 @@ export default function FeesDrawerLiveApp({
return updatedTransaction;
});
},
[setTransaction, bridge, mainAccount],
[setTransaction, bridge, mainAccount, swapDefaultTrack, track],
);

const mapStrategies = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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<typeof useLocation> &
Props["location"] & {
Expand All @@ -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 = {
Expand Down

0 comments on commit a541e82

Please sign in to comment.