File tree Expand file tree Collapse file tree 4 files changed +55
-1
lines changed
app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage) Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11"use client" ;
22
33import { useTheme } from "next-themes" ;
4- import { useState } from "react" ;
4+ import { useEffect , useRef , useState } from "react" ;
55import type { Chain , ThirdwebClient } from "thirdweb" ;
66import { BuyWidget , SwapWidget } from "thirdweb/react" ;
77import {
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" >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import { TeamHeader } from "../../../../team/components/TeamHeader/team-header";
2424import { StarButton } from "../../components/client/star-button" ;
2525import { getChain , getChainMetadata } from "../../utils" ;
2626import { AddChainToWallet } from "./components/client/add-chain-to-wallet" ;
27+ import { ChainPageView } from "./components/client/chain-pageview" ;
2728import { 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 >
You can’t perform that action at this time.
0 commit comments