diff --git a/src/analytics/Properties.tsx b/src/analytics/Properties.tsx index 9bb62e9cf13..9c4cefc0230 100644 --- a/src/analytics/Properties.tsx +++ b/src/analytics/Properties.tsx @@ -1127,6 +1127,7 @@ type SwapQuoteEvent = SwapEvent & { appFeePercentageIncludedInPrice: string | null | undefined provider: string swapType: SwapType + swapId: string } export interface SwapTimeMetrics { diff --git a/src/swap/SwapScreen.test.tsx b/src/swap/SwapScreen.test.tsx index 4252a6bcc63..01eaeedc090 100644 --- a/src/swap/SwapScreen.test.tsx +++ b/src/swap/SwapScreen.test.tsx @@ -42,6 +42,7 @@ import { mockTokenBalances, mockUSDCTokenId, } from 'test/values' +import { v4 as uuidv4 } from 'uuid' const mockFetch = fetch as FetchMock const mockGetNumberFormatSettings = jest.fn() @@ -79,6 +80,12 @@ jest.mock('src/viem/estimateFeesPerGas', () => ({ })), })) +jest.mock('uuid', () => ({ + v4: jest.fn().mockReturnValue('mocked-uuid'), +})) + +const mockedUuidv4 = uuidv4 as jest.Mock + const mockStoreTokenBalances = { [mockCeurTokenId]: { ...mockTokenBalances[mockCeurTokenId], @@ -1221,6 +1228,10 @@ describe('SwapScreen', () => { it('should have correct analytics on swap submission', async () => { mockFetch.mockResponse(defaultQuoteResponse) + + const mockSwapId = 'test-swap-id' + mockedUuidv4.mockReturnValue(mockSwapId) + const { getByText, swapScreen } = renderScreen({}) selectSwapTokens('CELO', 'cUSD', swapScreen) @@ -1261,6 +1272,7 @@ describe('SwapScreen', () => { feeCurrencySymbol: 'CELO', txCount: 2, swapType: 'same-chain', + swapId: mockSwapId, }) }) diff --git a/src/swap/SwapScreen.tsx b/src/swap/SwapScreen.tsx index 43812c1d1ec..4aa4607e9bf 100644 --- a/src/swap/SwapScreen.tsx +++ b/src/swap/SwapScreen.tsx @@ -406,7 +406,10 @@ export function SwapScreen({ route }: Props) { // to confirm the swap in this case. break case 'possible': + const swapId = uuidv4() + AppAnalytics.track(SwapEvents.swap_review_submit, { + swapId, toToken: toToken.address, toTokenId: toToken.tokenId, toTokenNetworkId: toToken.networkId, @@ -431,7 +434,6 @@ export function SwapScreen({ route }: Props) { ), }) - const swapId = uuidv4() localDispatch(startSwap({ swapId })) dispatch( swapStart({ diff --git a/src/swap/SwapScreenV2.test.tsx b/src/swap/SwapScreenV2.test.tsx index 82c02b248a4..483fb86c69b 100644 --- a/src/swap/SwapScreenV2.test.tsx +++ b/src/swap/SwapScreenV2.test.tsx @@ -43,6 +43,7 @@ import { mockTokenBalances, mockUSDCTokenId, } from 'test/values' +import { v4 as uuidv4 } from 'uuid' const mockFetch = fetch as FetchMock const mockGetNumberFormatSettings = jest.fn() @@ -80,6 +81,12 @@ jest.mock('src/viem/estimateFeesPerGas', () => ({ })), })) +jest.mock('uuid', () => ({ + v4: jest.fn().mockReturnValue('mocked-uuid'), +})) + +const mockedUuidv4 = uuidv4 as jest.Mock + const mockStoreTokenBalances = { [mockCeurTokenId]: { ...mockTokenBalances[mockCeurTokenId], @@ -1313,6 +1320,10 @@ describe('SwapScreen', () => { it('should have correct analytics on swap submission', async () => { mockFetch.mockResponse(defaultQuoteResponse) + + const mockSwapId = 'test-swap-id' + mockedUuidv4.mockReturnValue(mockSwapId) + const { getByText, swapScreen } = renderScreen({}) selectSwapTokens('CELO', 'cUSD', swapScreen) @@ -1353,6 +1364,7 @@ describe('SwapScreen', () => { feeCurrencySymbol: 'CELO', txCount: 2, swapType: 'same-chain', + swapId: mockSwapId, }) }) diff --git a/src/swap/SwapScreenV2.tsx b/src/swap/SwapScreenV2.tsx index a48549ec1c0..fb4067c268f 100644 --- a/src/swap/SwapScreenV2.tsx +++ b/src/swap/SwapScreenV2.tsx @@ -463,7 +463,10 @@ export default function SwapScreenV2({ route }: Props) { // to confirm the swap in this case. break case 'possible': + const swapId = uuidv4() + AppAnalytics.track(SwapEvents.swap_review_submit, { + swapId, toToken: toToken.address, toTokenId: toToken.tokenId, toTokenNetworkId: toToken.networkId, @@ -488,7 +491,6 @@ export default function SwapScreenV2({ route }: Props) { ), }) - const swapId = uuidv4() setStartedSwapId(swapId) dispatch( swapStart({ diff --git a/src/swap/saga.test.ts b/src/swap/saga.test.ts index 5e25ad93406..162a216540c 100644 --- a/src/swap/saga.test.ts +++ b/src/swap/saga.test.ts @@ -506,6 +506,7 @@ describe(swapSubmitSaga, () => { swapTxHash: '0x2', areSwapTokensShuffled: false, swapType: 'same-chain', + swapId: 'test-swap-id', }) const analyticsProps = (AppAnalytics.track as jest.Mock).mock.calls[0][1] @@ -787,6 +788,7 @@ describe(swapSubmitSaga, () => { swapTxHash: undefined, areSwapTokensShuffled: false, swapType: 'same-chain', + swapId: 'test-swap-id', }) const analyticsProps = (AppAnalytics.track as jest.Mock).mock.calls[0][1] expect(analyticsProps.gas).toBeCloseTo( diff --git a/src/swap/saga.ts b/src/swap/saga.ts index c097d9c4e45..20757ccfa1d 100644 --- a/src/swap/saga.ts +++ b/src/swap/saga.ts @@ -290,6 +290,7 @@ export function* swapSubmitSaga(action: PayloadAction) { ...getTimeMetrics(), ...getSwapTxsReceiptAnalyticsProperties(trackedTxs, networkId, tokensById), swapType, + swapId, }) } } catch (err) { @@ -315,6 +316,7 @@ export function* swapSubmitSaga(action: PayloadAction) { ...getTimeMetrics(), ...getSwapTxsReceiptAnalyticsProperties(trackedTxs, networkId, tokensById), error: error.message, + swapId, }) } }