diff --git a/src/components/tx/SignOrExecuteForm/index.tsx b/src/components/tx/SignOrExecuteForm/index.tsx index fa25fced45..e85ad42121 100644 --- a/src/components/tx/SignOrExecuteForm/index.tsx +++ b/src/components/tx/SignOrExecuteForm/index.tsx @@ -22,7 +22,7 @@ import useDecodeTx from '@/hooks/useDecodeTx' import { ErrorBoundary } from '@sentry/react' import ApprovalEditor from '../ApprovalEditor' import { isDelegateCall } from '@/services/tx/tx-sender/sdk' -import { getTransactionTrackingParams } from '@/services/analytics/tx-tracking' +import { getTransactionTrackingType } from '@/services/analytics/tx-tracking' import { TX_EVENTS } from '@/services/analytics/events/transactions' import { trackEvent } from '@/services/analytics' import useChainId from '@/hooks/useChainId' @@ -46,13 +46,12 @@ export type SignOrExecuteProps = { const trackTxEvents = async (chainId: string, txId: string, isCreation: boolean, isExecuted: boolean) => { const event = isCreation ? TX_EVENTS.CREATE : isExecuted ? TX_EVENTS.EXECUTE : TX_EVENTS.CONFIRM - const txParams = await getTransactionTrackingParams(chainId, txId) - const { type, ...rest } = txParams - trackEvent({ ...event, label: txParams.type, ...rest }) + const txType = await getTransactionTrackingType(chainId, txId) + trackEvent({ ...event, label: txType }) // Immediate execution on creation if (isCreation && isExecuted) { - trackEvent({ ...TX_EVENTS.EXECUTE, label: txParams.type, ...rest }) + trackEvent({ ...TX_EVENTS.EXECUTE, label: txType }) } } diff --git a/src/features/speedup/components/SpeedUpModal.tsx b/src/features/speedup/components/SpeedUpModal.tsx index 1cfbfdb188..8705f4bec8 100644 --- a/src/features/speedup/components/SpeedUpModal.tsx +++ b/src/features/speedup/components/SpeedUpModal.tsx @@ -23,7 +23,7 @@ import { PendingTxType, type PendingProcessingTx } from '@/store/pendingTxsSlice import useAsync from '@/hooks/useAsync' import { MODALS_EVENTS, trackEvent } from '@/services/analytics' import { TX_EVENTS } from '@/services/analytics/events/transactions' -import { getTransactionTrackingParams } from '@/services/analytics/tx-tracking' +import { getTransactionTrackingType } from '@/services/analytics/tx-tracking' import { trackError } from '@/services/exceptions' import ErrorCodes from '@/services/exceptions/ErrorCodes' @@ -97,8 +97,8 @@ export const SpeedUpModal = ({ chainInfo.chainId, safeAddress, ) - const trackingParams = await getTransactionTrackingParams(chainInfo.chainId, txId) - trackEvent({ ...TX_EVENTS.SPEED_UP, label: trackingParams.type }) + const txType = await getTransactionTrackingType(chainInfo.chainId, txId) + trackEvent({ ...TX_EVENTS.SPEED_UP, label: txType }) } else { await dispatchCustomTxSpeedUp( txOptions as Omit & { nonce: number }, diff --git a/src/hooks/useTxTracking.ts b/src/hooks/useTxTracking.ts index 833897647c..857e89f284 100644 --- a/src/hooks/useTxTracking.ts +++ b/src/hooks/useTxTracking.ts @@ -1,7 +1,6 @@ import { trackEvent, WALLET_EVENTS } from '@/services/analytics' import { getTxDetails } from '@/services/transactions' import { TxEvent, txSubscribe } from '@/services/tx/txEvents' -import { isSwapTxInfo } from '@/utils/transaction-guards' import { useEffect } from 'react' import useChainId from './useChainId' @@ -23,20 +22,17 @@ export const useTxTracking = (): void => { const id = txId || txHash let origin = '' - let transaction_id if (id) { try { const txDetails = await getTxDetails(chainId, id) origin = txDetails.safeAppInfo?.url || '' - transaction_id = isSwapTxInfo(txDetails.txInfo) ? txDetails.txInfo.uid : undefined } catch {} } trackEvent({ ...analyticsEvent, label: origin, - transaction_id, }) }), ) diff --git a/src/services/analytics/__tests__/tx-tracking.test.ts b/src/services/analytics/__tests__/tx-tracking.test.ts index 51615ed58c..41705985ca 100644 --- a/src/services/analytics/__tests__/tx-tracking.test.ts +++ b/src/services/analytics/__tests__/tx-tracking.test.ts @@ -6,12 +6,12 @@ import { TX_TYPES } from '../events/transactions' const getMockTxType = (txDetails: unknown) => { jest.spyOn(txDetailsModule, 'getTxDetails').mockImplementation(() => Promise.resolve(txDetails as TransactionDetails)) - return getTransactionTrackingType(txDetails as TransactionDetails) + return getTransactionTrackingType('1', '0x123') } describe('getTransactionTrackingType', () => { it('should return transfer_token for native token transfers', async () => { - const txType = getMockTxType({ + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.TRANSFER, transferInfo: { @@ -24,7 +24,7 @@ describe('getTransactionTrackingType', () => { }) it('should return transfer_token for ERC20 token transfers', async () => { - const txType = getMockTxType({ + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.TRANSFER, transferInfo: { @@ -37,7 +37,7 @@ describe('getTransactionTrackingType', () => { }) it('should return transfer_nft for ERC721 token transfers', async () => { - const txType = getMockTxType({ + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.TRANSFER, transferInfo: { @@ -50,7 +50,7 @@ describe('getTransactionTrackingType', () => { }) it('should return owner_add for add owner settings changes', async () => { - const txType = getMockTxType({ + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.SETTINGS_CHANGE, settingsInfo: { @@ -63,7 +63,7 @@ describe('getTransactionTrackingType', () => { }) it('should return owner_remove for remove owner settings changes', async () => { - const txType = getMockTxType({ + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.SETTINGS_CHANGE, settingsInfo: { @@ -75,8 +75,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.owner_remove) }) - it('should return owner_swap for swap owner settings changes', () => { - const txType = getMockTxType({ + it('should return owner_swap for swap owner settings changes', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.SETTINGS_CHANGE, settingsInfo: { @@ -88,8 +88,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.owner_swap) }) - it('should return owner_threshold_change for change threshold settings changes', () => { - const txType = getMockTxType({ + it('should return owner_threshold_change for change threshold settings changes', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.SETTINGS_CHANGE, settingsInfo: { @@ -101,8 +101,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.owner_threshold_change) }) - it('should return module_remove for disable module settings changes', () => { - const txType = getMockTxType({ + it('should return module_remove for disable module settings changes', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.SETTINGS_CHANGE, settingsInfo: { @@ -114,8 +114,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.module_remove) }) - it('should return guard_remove for delete guard settings changes', () => { - const txType = getMockTxType({ + it('should return guard_remove for delete guard settings changes', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.SETTINGS_CHANGE, settingsInfo: { @@ -127,8 +127,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.guard_remove) }) - it('should return rejection for rejection transactions', () => { - const txType = getMockTxType({ + it('should return rejection for rejection transactions', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.CUSTOM, isCancellation: true, @@ -138,8 +138,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.rejection) }) - it('should return walletconnect for walletconnect transactions', () => { - const txType = getMockTxType({ + it('should return walletconnect for walletconnect transactions', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.CUSTOM, }, @@ -151,8 +151,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.walletconnect) }) - it('should return safeapps for safeapps transactions', () => { - const txType = getMockTxType({ + it('should return safeapps for safeapps transactions', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.CUSTOM, }, @@ -164,8 +164,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual('https://gnosis-safe.io/app') }) - it('should return batch for multisend transactions', () => { - const txType = getMockTxType({ + it('should return batch for multisend transactions', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.CUSTOM, methodName: 'multiSend', @@ -176,8 +176,8 @@ describe('getTransactionTrackingType', () => { expect(txType).toEqual(TX_TYPES.batch) }) - it('should return custom for unknown transactions', () => { - const txType = getMockTxType({ + it('should return custom for unknown transactions', async () => { + const txType = await getMockTxType({ txInfo: { type: TransactionInfoType.CUSTOM, }, diff --git a/src/services/analytics/gtm.ts b/src/services/analytics/gtm.ts index 08317a7d1e..cb004e7de9 100644 --- a/src/services/analytics/gtm.ts +++ b/src/services/analytics/gtm.ts @@ -16,7 +16,7 @@ import { GOOGLE_TAG_MANAGER_AUTH_LATEST, GOOGLE_TAG_MANAGER_DEVELOPMENT_AUTH, } from '@/config/constants' -import type { AnalyticsEvent, EventLabel, SafeAppSDKEvent, GADimensions } from './types' +import type { AnalyticsEvent, EventLabel, SafeAppSDKEvent } from './types' import { EventType, DeviceType } from './types' import { SAFE_APPS_SDK_CATEGORY } from './events' import { getAbTest } from '../tracking/abTesting' @@ -107,35 +107,28 @@ type SafeAppGtmEvent = ActionGtmEvent & { const gtmSend = TagManager.dataLayer -export const gtmTrack = (eventData: AnalyticsEvent & Partial): void => { - const { event, category, action, chainId, label, ...rest } = eventData - - const gtmEvent: ActionGtmEvent & Partial = { +export const gtmTrack = (eventData: AnalyticsEvent): void => { + const gtmEvent: ActionGtmEvent = { ...commonEventParams, - event: event || EventType.CLICK, - eventCategory: category, - eventAction: action, - chainId: chainId || commonEventParams.chainId, - ...rest, + event: eventData.event || EventType.CLICK, + eventCategory: eventData.category, + eventAction: eventData.action, + chainId: eventData.chainId || commonEventParams.chainId, } - if (event) { - gtmEvent.eventType = event + if (eventData.event) { + gtmEvent.eventType = eventData.event } else { gtmEvent.eventType = undefined } - if (label !== undefined) { - gtmEvent.eventLabel = label + if (eventData.label !== undefined) { + gtmEvent.eventLabel = eventData.label } else { // Otherwise, whatever was in the datalayer before will be reused gtmEvent.eventLabel = undefined } - if (rest.transaction_id === undefined) { - gtmEvent.transaction_id = undefined - } - const abTest = getAbTest() if (abTest) { diff --git a/src/services/analytics/tx-tracking.ts b/src/services/analytics/tx-tracking.ts index 7011e9738a..6073c1a489 100644 --- a/src/services/analytics/tx-tracking.ts +++ b/src/services/analytics/tx-tracking.ts @@ -1,5 +1,4 @@ import { TX_TYPES } from '@/services/analytics/events/transactions' -import type { GADimensions } from '@/services/analytics/types' import { getTxDetails } from '@/services/transactions' import { isWalletConnectSafeApp } from '@/utils/gateway' import { SettingsInfoType, type TransactionDetails } from '@safe-global/safe-gateway-typescript-sdk' @@ -13,30 +12,15 @@ import { isSwapTxInfo, } from '@/utils/transaction-guards' -type TrackingParams = { - type: string -} & Partial - -export const getTransactionTrackingParams = async (chainId: string, txId: string): Promise => { +export const getTransactionTrackingType = async (chainId: string, txId: string): Promise => { let details: TransactionDetails try { details = await getTxDetails(chainId, txId) } catch { - return { - type: TX_TYPES.custom, - } - } - - const type = getTransactionTrackingType(details) - - return { - type, - transaction_id: isSwapTxInfo(details.txInfo) ? details.txInfo.uid : undefined, + return TX_TYPES.custom } -} -export const getTransactionTrackingType = (details: TransactionDetails): string => { const { txInfo } = details if (isTransferTxInfo(txInfo)) { diff --git a/src/services/analytics/types.ts b/src/services/analytics/types.ts index e5013c9c01..855b791403 100644 --- a/src/services/analytics/types.ts +++ b/src/services/analytics/types.ts @@ -25,11 +25,6 @@ export type AnalyticsEvent = { chainId?: string } -// https://support.google.com/analytics/answer/9143382 -export type GADimensions = { - transaction_id: string -} - export type SafeAppSDKEvent = { method: string ethMethod: string