Skip to content

Commit eed734c

Browse files
[SDK] feat: Add pay event tracking for transaction modal states (#5971)
1 parent a3a3062 commit eed734c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/thirdweb/src/analytics/track/pay.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function trackPayEvent(args: {
1717
toAmount?: string;
1818
chainId?: number;
1919
dstChainId?: number;
20+
error?: string;
2021
}) {
2122
return track({
2223
client: args.client,
@@ -32,6 +33,7 @@ export async function trackPayEvent(args: {
3233
amountWei: args.fromAmount,
3334
dstTokenAddress: args.toToken,
3435
dstChainId: args.chainId,
36+
errorCode: args.error,
3537
},
3638
});
3739
}

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type UseMutationResult, useMutation } from "@tanstack/react-query";
2+
import { trackPayEvent } from "../../../../analytics/track/pay.js";
23
import type { Chain } from "../../../../chains/types.js";
34
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
45
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
@@ -146,6 +147,13 @@ export function useSendTransactionCore(args: {
146147
}
147148

148149
if (!showPayModal) {
150+
trackPayEvent({
151+
client: tx.client,
152+
walletAddress: account.address,
153+
walletType: wallet?.id,
154+
dstChainId: tx.chain.id,
155+
event: "pay_transaction_modal_disabled",
156+
});
149157
return sendTransaction({
150158
transaction: tx,
151159
account,
@@ -174,7 +182,17 @@ export function useSendTransactionCore(args: {
174182
await Promise.all([
175183
resolvePromisedValue(tx.value),
176184
resolvePromisedValue(tx.erc20Value),
177-
fetchBuySupportedDestinations(tx.client).catch(() => null),
185+
fetchBuySupportedDestinations(tx.client).catch((err) => {
186+
trackPayEvent({
187+
client: tx.client,
188+
walletAddress: account.address,
189+
walletType: wallet?.id,
190+
dstChainId: tx.chain.id,
191+
event: "pay_transaction_modal_pay_api_error",
192+
error: err?.message,
193+
});
194+
return null;
195+
}),
178196
]);
179197

180198
if (!supportedDestinations) {
@@ -198,6 +216,14 @@ export function useSendTransactionCore(args: {
198216
),
199217
))
200218
) {
219+
trackPayEvent({
220+
client: tx.client,
221+
walletAddress: account.address,
222+
walletType: wallet?.id,
223+
dstChainId: tx.chain.id,
224+
event: "pay_transaction_modal_chain_token_not_supported",
225+
error: `chain ${tx.chain.id} ${_erc20Value ? `/ token ${_erc20Value?.tokenAddress}` : ""} not supported`,
226+
});
201227
// chain/token not supported, just send the tx
202228
sendTx();
203229
return;
@@ -241,6 +267,13 @@ export function useSendTransactionCore(args: {
241267
resolveTx: resolve,
242268
});
243269
} else {
270+
trackPayEvent({
271+
client: tx.client,
272+
walletAddress: account.address,
273+
walletType: wallet?.id,
274+
dstChainId: tx.chain.id,
275+
event: "pay_transaction_modal_has_enough_funds",
276+
});
244277
sendTx();
245278
}
246279
} catch (e) {

0 commit comments

Comments
 (0)