Skip to content

Commit 031e629

Browse files
committed
feat: adds ub widget tracking
1 parent 66270f7 commit 031e629

File tree

15 files changed

+216
-6
lines changed

15 files changed

+216
-6
lines changed

packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export function BridgeOrchestrator({
217217
{/* Error Banner */}
218218
{state.value === "error" && state.context.currentError && (
219219
<ErrorBanner
220+
client={client}
220221
error={state.context.currentError}
221222
onCancel={onCancel}
222223
onRetry={handleRetry}
@@ -332,6 +333,7 @@ export function BridgeOrchestrator({
332333
state.context.quote &&
333334
state.context.completedStatuses && (
334335
<SuccessScreen
336+
client={client}
335337
completedStatuses={state.context.completedStatuses}
336338
onDone={handleBuyComplete}
337339
preparedQuote={state.context.quote}

packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useQuery } from "@tanstack/react-query";
4+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
45
import type { Token } from "../../../../bridge/index.js";
56
import type { Chain } from "../../../../chains/types.js";
67
import type { ThirdwebClient } from "../../../../client/client.js";
@@ -268,6 +269,18 @@ export function BuyWidget(props: BuyWidgetProps) {
268269
const localeQuery = useConnectLocale(props.locale || "en_US");
269270
const theme = props.theme || "dark";
270271

272+
useQuery({
273+
queryFn: () => {
274+
trackPayEvent({
275+
client: props.client,
276+
event: "buy_widget:render",
277+
toChainId: props.chain.id,
278+
toToken: props.tokenAddress,
279+
});
280+
},
281+
queryKey: ["buy_widget:render"],
282+
});
283+
271284
const bridgeDataQuery = useQuery({
272285
queryFn: async (): Promise<UIOptionsResult> => {
273286
if (
@@ -343,7 +356,13 @@ export function BuyWidget(props: BuyWidgetProps) {
343356
);
344357
} else if (bridgeDataQuery.data?.type === "unsupported_token") {
345358
// Show unsupported token screen
346-
content = <UnsupportedTokenScreen chain={bridgeDataQuery.data.chain} />;
359+
content = (
360+
<UnsupportedTokenScreen
361+
chain={bridgeDataQuery.data.chain}
362+
client={props.client}
363+
tokenAddress={props.tokenAddress}
364+
/>
365+
);
347366
} else if (bridgeDataQuery.data?.type === "success") {
348367
// Show normal bridge orchestrator
349368
content = (

packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useQuery } from "@tanstack/react-query";
4+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
45
import type { Token } from "../../../../bridge/index.js";
56
import type { Chain } from "../../../../chains/types.js";
67
import type { ThirdwebClient } from "../../../../client/client.js";
@@ -251,6 +252,18 @@ export function CheckoutWidget(props: CheckoutWidgetProps) {
251252
const localeQuery = useConnectLocale(props.locale || "en_US");
252253
const theme = props.theme || "dark";
253254

255+
useQuery({
256+
queryFn: () => {
257+
trackPayEvent({
258+
client: props.client,
259+
event: "checkout_widget:render",
260+
toChainId: props.chain.id,
261+
toToken: props.tokenAddress,
262+
});
263+
},
264+
queryKey: ["checkout_widget:render"],
265+
});
266+
254267
const bridgeDataQuery = useQuery({
255268
queryFn: async (): Promise<UIOptionsResult> => {
256269
const token = await getToken(
@@ -306,7 +319,13 @@ export function CheckoutWidget(props: CheckoutWidgetProps) {
306319
);
307320
} else if (bridgeDataQuery.data?.type === "unsupported_token") {
308321
// Show unsupported token screen
309-
content = <UnsupportedTokenScreen chain={bridgeDataQuery.data.chain} />;
322+
content = (
323+
<UnsupportedTokenScreen
324+
chain={bridgeDataQuery.data.chain}
325+
client={props.client}
326+
tokenAddress={props.tokenAddress}
327+
/>
328+
);
310329
} else if (bridgeDataQuery.data?.type === "success") {
311330
// Show normal bridge orchestrator
312331
content = (

packages/thirdweb/src/react/web/ui/Bridge/ErrorBanner.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"use client";
22
import { CrossCircledIcon } from "@radix-ui/react-icons";
3+
import { useQuery } from "@tanstack/react-query";
4+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
5+
import type { ThirdwebClient } from "../../../../client/client.js";
36
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
47
import { iconSize } from "../../../core/design-system/index.js";
58
import { useBridgeError } from "../../../core/hooks/useBridgeError.js";
@@ -22,13 +25,30 @@ interface ErrorBannerProps {
2225
* Called when user wants to cancel
2326
*/
2427
onCancel?: () => void;
28+
client: ThirdwebClient;
2529
}
2630

27-
export function ErrorBanner({ error, onRetry, onCancel }: ErrorBannerProps) {
31+
export function ErrorBanner({
32+
error,
33+
onRetry,
34+
onCancel,
35+
client,
36+
}: ErrorBannerProps) {
2837
const theme = useCustomTheme();
2938

3039
const { userMessage } = useBridgeError({ error });
3140

41+
useQuery({
42+
queryFn: () => {
43+
trackPayEvent({
44+
client,
45+
error: error.message,
46+
event: "error",
47+
});
48+
},
49+
queryKey: ["error_banner", userMessage],
50+
});
51+
3252
return (
3353
<Container flex="column" fullHeight gap="md" p="lg">
3454
{/* Error Icon and Message */}

packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client";
2+
import { useQuery } from "@tanstack/react-query";
23
import { useEffect } from "react";
4+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
35
import type { Token } from "../../../../bridge/types/Token.js";
46
import type { ThirdwebClient } from "../../../../client/client.js";
57
import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
@@ -109,6 +111,26 @@ export function QuoteLoader({
109111
});
110112
const prepareQuery = useBridgePrepare(request);
111113

114+
useQuery({
115+
queryFn: () => {
116+
trackPayEvent({
117+
chainId:
118+
paymentMethod.type === "wallet"
119+
? paymentMethod.originToken.chainId
120+
: undefined,
121+
client,
122+
event: "loading_quote",
123+
fromToken:
124+
paymentMethod.type === "wallet"
125+
? paymentMethod.originToken.address
126+
: undefined,
127+
toChainId: destinationToken.chainId,
128+
toToken: destinationToken.address,
129+
});
130+
},
131+
queryKey: ["loading_quote", paymentMethod.type],
132+
});
133+
112134
// Handle successful quote
113135
useEffect(() => {
114136
if (prepareQuery.data) {

packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useQuery } from "@tanstack/react-query";
4+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
45
import type { Token } from "../../../../bridge/index.js";
56
import type { Chain } from "../../../../chains/types.js";
67
import type { ThirdwebClient } from "../../../../client/client.js";
@@ -275,6 +276,18 @@ export function TransactionWidget(props: TransactionWidgetProps) {
275276
const localeQuery = useConnectLocale(props.locale || "en_US");
276277
const theme = props.theme || "dark";
277278

279+
useQuery({
280+
queryFn: () => {
281+
trackPayEvent({
282+
chainId: props.transaction.chain.id,
283+
client: props.client,
284+
event: "transaction_widget:render",
285+
toToken: props.tokenAddress,
286+
});
287+
},
288+
queryKey: ["transaction_widget:render"],
289+
});
290+
278291
const bridgeDataQuery = useQuery({
279292
queryFn: async (): Promise<UIOptionsResult> => {
280293
let erc20Value = props.transaction.erc20Value;
@@ -331,7 +344,13 @@ export function TransactionWidget(props: TransactionWidgetProps) {
331344
);
332345
} else if (bridgeDataQuery.data?.type === "unsupported_token") {
333346
// Show unsupported token screen
334-
content = <UnsupportedTokenScreen chain={bridgeDataQuery.data.chain} />;
347+
content = (
348+
<UnsupportedTokenScreen
349+
chain={bridgeDataQuery.data.chain}
350+
client={props.client}
351+
tokenAddress={props.tokenAddress}
352+
/>
353+
);
335354
} else if (bridgeDataQuery.data?.type === "success") {
336355
// Show normal bridge orchestrator
337356
content = (

packages/thirdweb/src/react/web/ui/Bridge/UnsupportedTokenScreen.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
13
import type { Chain } from "../../../../chains/types.js";
4+
import type { ThirdwebClient } from "../../../../client/client.js";
25
import { iconSize } from "../../../core/design-system/index.js";
36
import { useChainMetadata } from "../../../core/hooks/others/useChainQuery.js";
47
import { AccentFailIcon } from "../ConnectWallet/icons/AccentFailIcon.js";
@@ -11,17 +14,31 @@ export interface UnsupportedTokenScreenProps {
1114
* The chain the token is on
1215
*/
1316
chain: Chain;
17+
client: ThirdwebClient;
18+
tokenAddress?: string;
1419
}
1520

1621
/**
1722
* Screen displayed when a specified token is not supported by the Bridge API
1823
* @internal
1924
*/
2025
export function UnsupportedTokenScreen(props: UnsupportedTokenScreenProps) {
21-
const { chain } = props;
26+
const { chain, tokenAddress, client } = props;
2227

2328
const { data: chainMetadata } = useChainMetadata(chain);
2429

30+
useQuery({
31+
queryFn: () => {
32+
trackPayEvent({
33+
chainId: chain.id,
34+
client,
35+
event: "unsupported_token",
36+
fromToken: tokenAddress,
37+
});
38+
},
39+
queryKey: ["unsupported_token"],
40+
});
41+
2542
if (chainMetadata?.testnet) {
2643
return (
2744
<Container

packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentDetails.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"use client";
2+
import { useQuery } from "@tanstack/react-query";
3+
import { trackPayEvent } from "../../../../../analytics/track/pay.js";
24
import type { ThirdwebClient } from "../../../../../client/client.js";
35
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
46
import { radius, spacing } from "../../../../core/design-system/index.js";
@@ -68,6 +70,22 @@ export function PaymentDetails({
6870
}
6971
};
7072

73+
useQuery({
74+
queryFn: () => {
75+
if (preparedQuote.type === "buy" || preparedQuote.type === "sell") {
76+
trackPayEvent({
77+
chainId: preparedQuote.intent.originChainId,
78+
client,
79+
event: "payment_details",
80+
fromToken: preparedQuote.intent.originTokenAddress,
81+
toChainId: preparedQuote.intent.destinationChainId,
82+
toToken: preparedQuote.intent.destinationTokenAddress,
83+
});
84+
}
85+
},
86+
queryKey: ["payment_details", preparedQuote.type],
87+
});
88+
7189
// Extract common data based on quote type
7290
const getDisplayData = () => {
7391
switch (preparedQuote.type) {

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/PaymentSelection.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client";
2+
import { useQuery } from "@tanstack/react-query";
23
import { useEffect, useState } from "react";
4+
import { trackPayEvent } from "../../../../../analytics/track/pay.js";
35
import type { Token } from "../../../../../bridge/types/Token.js";
46
import { defineChain } from "../../../../../chains/utils.js";
57
import type { ThirdwebClient } from "../../../../../client/client.js";
@@ -96,6 +98,18 @@ export function PaymentSelection({
9698
type: "walletSelection",
9799
});
98100

101+
useQuery({
102+
queryFn: () => {
103+
trackPayEvent({
104+
client,
105+
event: "payment_selection",
106+
toChainId: destinationToken.chainId,
107+
toToken: destinationToken.address,
108+
});
109+
},
110+
queryKey: ["payment_selection"],
111+
});
112+
99113
const payerWallet =
100114
currentStep.type === "tokenSelection"
101115
? currentStep.selectedWallet

packages/thirdweb/src/react/web/ui/Bridge/payment-success/SuccessScreen.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use client";
22
import { CheckIcon } from "@radix-ui/react-icons";
3+
import { useQuery } from "@tanstack/react-query";
34
import { useState } from "react";
5+
import { trackPayEvent } from "../../../../../analytics/track/pay.js";
6+
import type { ThirdwebClient } from "../../../../../client/client.js";
47
import type { WindowAdapter } from "../../../../core/adapters/WindowAdapter.js";
58
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
69
import { iconSize } from "../../../../core/design-system/index.js";
@@ -37,6 +40,8 @@ export interface SuccessScreenProps {
3740
* Window adapter for opening URLs
3841
*/
3942
windowAdapter: WindowAdapter;
43+
44+
client: ThirdwebClient;
4045
}
4146

4247
type ViewState = "success" | "detail";
@@ -47,10 +52,27 @@ export function SuccessScreen({
4752
completedStatuses,
4853
onDone,
4954
windowAdapter,
55+
client,
5056
}: SuccessScreenProps) {
5157
const theme = useCustomTheme();
5258
const [viewState, setViewState] = useState<ViewState>("success");
5359

60+
useQuery({
61+
queryFn: () => {
62+
if (preparedQuote.type === "buy" || preparedQuote.type === "sell") {
63+
trackPayEvent({
64+
chainId: preparedQuote.intent.originChainId,
65+
client: client,
66+
event: "success_screen",
67+
fromToken: preparedQuote.intent.originTokenAddress,
68+
toChainId: preparedQuote.intent.destinationChainId,
69+
toToken: preparedQuote.intent.destinationTokenAddress,
70+
});
71+
}
72+
},
73+
queryKey: ["success_screen", preparedQuote.type],
74+
});
75+
5476
if (viewState === "detail") {
5577
return (
5678
<PaymentReceipt

0 commit comments

Comments
 (0)