File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-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
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" >
You can’t perform that action at this time.
0 commit comments