Skip to content

Commit 7db060a

Browse files
committed
Dashboard: Add tracking for SwapWidget impression
1 parent 4482692 commit 7db060a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

apps/dashboard/src/@/analytics/report.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@ export function reportTokenSwapSuccessful(properties: TokenSwapParams) {
255255
posthog.capture("token swap successful", properties);
256256
}
257257

258+
/**
259+
* ### Why do we need to report this event?
260+
* - To track impressions of the swap widget
261+
* - To create a funnel "swap widget shown" -> "swap widget successful" to understand the conversion rate
262+
*
263+
* ### Who is responsible for this event?
264+
* @MananTank
265+
*/
266+
export function reportSwapWidgetShown(properties: {
267+
pageType: "asset" | "bridge" | "chain";
268+
}) {
269+
posthog.capture("swap widget shown", properties);
270+
}
271+
258272
/**
259273
* ### Why do we need to report this event?
260274
* - To track number of failed token swaps from the token page

apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use client";
22

33
import { useTheme } from "next-themes";
4-
import { useState } from "react";
4+
import { useEffect, useRef, useState } from "react";
55
import type { Chain, ThirdwebClient } from "thirdweb";
66
import { BuyWidget, SwapWidget } from "thirdweb/react";
77
import {
88
reportAssetBuyCancelled,
99
reportAssetBuyFailed,
1010
reportAssetBuySuccessful,
11+
reportSwapWidgetShown,
1112
reportTokenSwapCancelled,
1213
reportTokenSwapFailed,
1314
reportTokenSwapSuccessful,
@@ -27,6 +28,19 @@ export function BuyAndSwapEmbed(props: {
2728
const { theme } = useTheme();
2829
const [tab, setTab] = useState<"buy" | "swap">("swap");
2930
const themeObj = getSDKTheme(theme === "light" ? "light" : "dark");
31+
const isMounted = useRef(false);
32+
33+
// eslint-disable-next-line no-restricted-syntax
34+
useEffect(() => {
35+
if (isMounted.current) {
36+
return;
37+
}
38+
isMounted.current = true;
39+
reportSwapWidgetShown({
40+
pageType: props.pageType,
41+
});
42+
}, [props.pageType]);
43+
3044
return (
3145
<div className="bg-card rounded-2xl border overflow-hidden flex flex-col">
3246
<div className="flex gap-2.5 p-4 border-b border-dashed">

0 commit comments

Comments
 (0)