Skip to content

Commit

Permalink
Merge pull request #5372 from EdgeApp/jon/analytics/swap-assets
Browse files Browse the repository at this point in the history
Add `isBuiltinAsset` to `Exchange_Shift_Success`
  • Loading branch information
Jon-edge authored Nov 26, 2024
2 parents ce37529 + 78edce3 commit 89d5c51
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: `isBuiltInAsset` param for 'Exchange_Shift_Success' tracking event

## 4.17.2

- fixed: (Zcash/Pirate) Fixed android build issues
Expand Down
14 changes: 11 additions & 3 deletions src/components/scenes/SwapConfirmationScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
31 changes: 30 additions & 1 deletion src/util/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 89d5c51

Please sign in to comment.