From 78edce372fd05deab6e30db8138626141dd4aac1 Mon Sep 17 00:00:00 2001 From: Jon Tzeng Date: Fri, 22 Nov 2024 14:41:15 -0800 Subject: [PATCH] Add `isBuiltinAsset` to `Exchange_Shift_Success` --- CHANGELOG.md | 2 ++ .../scenes/SwapConfirmationScene.tsx | 14 +++++++-- src/util/tracking.ts | 31 ++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8126149e024..c2995909bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- added: `isBuiltInAsset` param for 'Exchange_Shift_Success' tracking event + ## 4.17.2 - fixed: (Zcash/Pirate) Fixed android build issues diff --git a/src/components/scenes/SwapConfirmationScene.tsx b/src/components/scenes/SwapConfirmationScene.tsx index 24e033fd995..da281bdc054 100644 --- a/src/components/scenes/SwapConfirmationScene.tsx +++ b/src/components/scenes/SwapConfirmationScene.tsx @@ -162,7 +162,7 @@ export const SwapConfirmationScene = (props: Props) => { const { fromDisplayAmount, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = await dispatch(getSwapInfo(selectedQuote)) const { isEstimate, fromNativeAmount, toNativeAmount, networkFee, pluginId, expirationDate, request } = selectedQuote // Both fromCurrencyCode and toCurrencyCode will exist, since we set them: - const { toWallet, toTokenId } = request + const { toWallet, toTokenId, fromWallet, fromTokenId } = request try { dispatch(logEvent('Exchange_Shift_Start')) const result: EdgeSwapResult = await selectedQuote.approve() @@ -199,12 +199,20 @@ export const SwapConfirmationScene = (props: Props) => { dispatch( logEvent('Exchange_Shift_Success', { conversionValues: { - conversionType: 'crypto', - cryptoAmount: new CryptoAmount({ + conversionType: 'swap', + destAmount: new CryptoAmount({ nativeAmount: toNativeAmount, tokenId: toTokenId, currencyConfig: toWallet.currencyConfig }), + sourceAmount: new CryptoAmount({ + nativeAmount: fromNativeAmount, + tokenId: fromTokenId, + currencyConfig: fromWallet.currencyConfig + }), + isBuiltInAsset: + (toTokenId == null || toWallet.currencyConfig.builtinTokens[toTokenId] != null) && + (fromTokenId == null || fromWallet.currencyConfig.builtinTokens[fromTokenId] != null), orderId: result.orderId, swapProviderId: pluginId } diff --git a/src/util/tracking.ts b/src/util/tracking.ts index 8c98b689b8b..5e0ed959648 100644 --- a/src/util/tracking.ts +++ b/src/util/tracking.ts @@ -80,6 +80,20 @@ export interface CryptoConversionValues { orderId?: string } +/** + * Analytics: Swap + */ +export interface SwapConversionValues { + conversionType: 'swap' + isBuiltInAsset: boolean + + destAmount: CryptoAmount + sourceAmount: CryptoAmount + + swapProviderId?: string + orderId?: string +} + /** * Analytics: Sell to fiat */ @@ -125,7 +139,7 @@ export interface TrackingValues extends LoginTrackingValues { surveyResponse?: string // User's answer to a survey // Conversion values - conversionValues?: DollarConversionValues | CryptoConversionValues | SellConversionValues | BuyConversionValues + conversionValues?: DollarConversionValues | CryptoConversionValues | SellConversionValues | BuyConversionValues | SwapConversionValues } // Set up the global Posthog analytics instance at boot @@ -255,6 +269,21 @@ export function logEvent(event: TrackingEventName, values: TrackingValues = {}): params.dollarValue = Math.abs(Number(cryptoAmount.displayDollarValue(exchangeRates))) + if (orderId != null) params.orderId = orderId + if (swapProviderId != null) params.swapProviderId = swapProviderId + } else if (conversionType === 'swap') { + const { destAmount, sourceAmount, swapProviderId, orderId, isBuiltInAsset } = conversionValues + + params.isBuiltInAsset = isBuiltInAsset + + params.sourceCryptoAmount = Math.abs(Number(sourceAmount.exchangeAmount)) + params.sourceCurrencyCode = sourceAmount.currencyCode + params.sourceDollarValue = Math.abs(Number(sourceAmount.displayDollarValue(exchangeRates))) + + params.destCryptoAmount = Math.abs(Number(destAmount.exchangeAmount)) + params.destCurrencyCode = destAmount.currencyCode + params.destDollarValue = Math.abs(Number(destAmount.displayDollarValue(exchangeRates))) + if (orderId != null) params.orderId = orderId if (swapProviderId != null) params.swapProviderId = swapProviderId }