Skip to content

Commit

Permalink
fix: Revert orderUid tracking (#3690)
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed May 13, 2024
1 parent 57bbcc5 commit 7b5ba97
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 77 deletions.
9 changes: 4 additions & 5 deletions src/components/tx/SignOrExecuteForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 })
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/features/speedup/components/SpeedUpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<TransactionOptions, 'nonce'> & { nonce: number },
Expand Down
4 changes: 0 additions & 4 deletions src/hooks/useTxTracking.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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,
})
}),
)
Expand Down
48 changes: 24 additions & 24 deletions src/services/analytics/__tests__/tx-tracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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',
Expand All @@ -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,
},
Expand Down
29 changes: 11 additions & 18 deletions src/services/analytics/gtm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -107,35 +107,28 @@ type SafeAppGtmEvent = ActionGtmEvent & {

const gtmSend = TagManager.dataLayer

export const gtmTrack = (eventData: AnalyticsEvent & Partial<GADimensions>): void => {
const { event, category, action, chainId, label, ...rest } = eventData

const gtmEvent: ActionGtmEvent & Partial<GADimensions> = {
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) {
Expand Down
20 changes: 2 additions & 18 deletions src/services/analytics/tx-tracking.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -13,30 +12,15 @@ import {
isSwapTxInfo,
} from '@/utils/transaction-guards'

type TrackingParams = {
type: string
} & Partial<GADimensions>

export const getTransactionTrackingParams = async (chainId: string, txId: string): Promise<TrackingParams> => {
export const getTransactionTrackingType = async (chainId: string, txId: string): Promise<string> => {
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)) {
Expand Down
5 changes: 0 additions & 5 deletions src/services/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit 7b5ba97

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 79.21% 11640/14696
🔴 Branches 58.16% 2755/4737
🟡 Functions 66.25% 1863/2812
🟢 Lines 80.55% 10490/13023

Test suite run success

1464 tests passing in 202 suites.

Report generated by 🧪jest coverage report action from 7b5ba97

Please sign in to comment.