Skip to content

Commit

Permalink
Collect more swap event data (#3276)
Browse files Browse the repository at this point in the history
* Log fiat value of token in not token out

* log failed tx and fee usd value
  • Loading branch information
jonator authored May 23, 2024
1 parent da9419d commit 86d806f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 12 additions & 15 deletions packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,22 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(

const baseEvent = {
fromToken: swapState.fromAsset?.coinDenom,
tokenAmount: Number(swapState.inAmountInput.amount),
tokenAmount: Number(swapState.inAmountInput.amount.toDec().toString()),
toToken: swapState.toAsset?.coinDenom,
isOnHome: page === "Swap Page",
isMultiHop: swapState.quote?.split.some(
({ pools }) => pools.length !== 1
),
isMultiRoute: (swapState.quote?.split.length ?? 0) > 1,
valueUsd: Number(
swapState.tokenOutFiatValue?.toDec().toString() ?? "0"
swapState.inAmountInput.fiatValue?.toDec().toString() ?? "0"
),
feeValueUsd: Number(swapState.totalFee?.toString() ?? "0"),
page,
quoteTimeMilliseconds: swapState.quote?.timeMs,
router: swapState.quote?.name,
};
logEvent([
EventName.Swap.swapStarted,
{
...baseEvent,
quoteTimeMilliseconds: swapState.quote?.timeMs,
router: swapState.quote?.name,
},
]);
logEvent([EventName.Swap.swapStarted, baseEvent]);
swapState
.sendTradeTokenInTx()
.then((result) => {
Expand All @@ -208,8 +204,6 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
{
...baseEvent,
isMultiHop: result === "multihop",
quoteTimeMilliseconds: swapState.quote?.timeMs,
router: swapState.quote?.name,
},
]);

Expand All @@ -221,9 +215,12 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
}
})
.catch((error) => {
// failed broadcast txs are handled elsewhere
// this is likely a signature rejection
console.error("swap error", error);
console.error("swap failed", error);
if (error instanceof Error && error.message === "Request rejected") {
// don't log when the user rejects in wallet
return;
}
logEvent([EventName.Swap.swapFailed, baseEvent]);
})
.finally(() => {
onRequestModalClose?.();
Expand Down
2 changes: 2 additions & 0 deletions packages/web/config/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type EventProperties = {
router: string;
errorMessage: string | undefined;
valueUsd: number;
feeValueUsd: number;
assetCategory: string;
highlight: string;
};
Expand All @@ -84,6 +85,7 @@ export const EventName = {
slippageToleranceSet: "Swap: Slippage tolerance set",
swapStarted: "Swap: Swap started",
swapCompleted: "Swap: Swap completed",
swapFailed: "Swap: Swap failed",
dropdownAssetSelected: "Swap: Dropdown asset selected",
},
// Events in Sidebar UI
Expand Down

0 comments on commit 86d806f

Please sign in to comment.