Skip to content

Commit f3b3b89

Browse files
committed
Dashboard: Add tracking for SwapWidget impression, chain pageview (#8071)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces analytics tracking for chain page views and enhances the reporting for swap widgets in the dashboard application. ### Detailed summary - Added `ChainPageView` component to track impressions of chain pages. - Integrated `reportChainPageview` function in the analytics module. - Enhanced `BuyAndSwapEmbed` to report when the swap widget is shown. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Chores - Added one-time telemetry when the Swap widget is displayed to improve usage insights. - Tracks the page context (asset, bridge, or chain) when the widget first appears. - Added one-time telemetry to record chain pageviews (captures the chain identifier) when visiting chain pages. - Integrated with existing UI; no impact on behavior, user action, or performance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 4482692 commit f3b3b89

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

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

Lines changed: 25 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
@@ -530,6 +544,17 @@ export function reportAssetPageview(properties: {
530544
posthog.capture("asset pageview", properties);
531545
}
532546

547+
/**
548+
* ### Why do we need to report this event?
549+
* - To understand which chains are being viewed the most
550+
*
551+
* ### Who is responsible for this event?
552+
* @MananTank
553+
*/
554+
export function reportChainPageview(properties: { chainId: number }) {
555+
posthog.capture("chain pageview", properties);
556+
}
557+
533558
/**
534559
* ### Why do we need to report this event?
535560
* - To track the usage of fund wallet modal

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">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use client";
2+
import { reportChainPageview } from "@/analytics/report";
3+
import { useEffectOnce } from "@/hooks/useEffectOnce";
4+
5+
export function ChainPageView(props: { chainId: number }) {
6+
useEffectOnce(() => {
7+
reportChainPageview({
8+
chainId: props.chainId,
9+
});
10+
});
11+
12+
return null;
13+
}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { TeamHeader } from "../../../../team/components/TeamHeader/team-header";
2424
import { StarButton } from "../../components/client/star-button";
2525
import { getChain, getChainMetadata } from "../../utils";
2626
import { AddChainToWallet } from "./components/client/add-chain-to-wallet";
27+
import { ChainPageView } from "./components/client/chain-pageview";
2728
import { ChainHeader } from "./components/server/chain-header";
2829

2930
// TODO: improve the behavior when clicking "Get started with thirdweb", currently just redirects to the dashboard
@@ -71,6 +72,7 @@ export default async function ChainPageLayout(props: {
7172

7273
return (
7374
<div className="flex grow flex-col">
75+
<ChainPageView chainId={chain.chainId} />
7476
<div className="border-border border-b bg-card">
7577
<TeamHeader />
7678
</div>

0 commit comments

Comments
 (0)