Skip to content

Commit

Permalink
Attach safe address to GTM (#2524)
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan authored Sep 20, 2023
1 parent 20eb921 commit 42633fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/services/analytics/gtm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const GTM_ENV_AUTH: Record<GTMEnvironment, GTMEnvironmentArgs> = {
const commonEventParams = {
chainId: '',
deviceType: DeviceType.DESKTOP,
safeAddress: '',
}

export const gtmSetChainId = (chainId: string): void => {
Expand All @@ -53,6 +54,10 @@ export const gtmSetDeviceType = (type: DeviceType): void => {
commonEventParams.deviceType = type
}

export const gtmSetSafeAddress = (safeAddress: string): void => {
commonEventParams.safeAddress = safeAddress
}

export const gtmInit = (): void => {
const GTM_ENVIRONMENT = IS_PRODUCTION ? GTM_ENV_AUTH.LIVE : GTM_ENV_AUTH.DEVELOPMENT

Expand Down
8 changes: 8 additions & 0 deletions src/services/analytics/useGtm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
gtmEnableCookies,
gtmDisableCookies,
gtmSetDeviceType,
gtmSetSafeAddress,
} from '@/services/analytics/gtm'
import { useAppSelector } from '@/store'
import { CookieType, selectCookies } from '@/store/cookiesSlice'
Expand All @@ -21,6 +22,7 @@ import { AppRoutes } from '@/config/routes'
import useMetaEvents from './useMetaEvents'
import { useMediaQuery } from '@mui/material'
import { DeviceType } from './types'
import useSafeAddress from '@/hooks/useSafeAddress'

const useGtm = () => {
const chainId = useChainId()
Expand All @@ -32,6 +34,7 @@ const useGtm = () => {
const isMobile = useMediaQuery(theme.breakpoints.down('sm'))
const isTablet = useMediaQuery(theme.breakpoints.down('md'))
const deviceType = isMobile ? DeviceType.MOBILE : isTablet ? DeviceType.TABLET : DeviceType.DESKTOP
const safeAddress = useSafeAddress()

// Initialize GTM
useEffect(() => {
Expand Down Expand Up @@ -63,6 +66,11 @@ const useGtm = () => {
gtmSetDeviceType(deviceType)
}, [deviceType])

// Set safe address for all GTM events
useEffect(() => {
gtmSetSafeAddress(safeAddress)
}, [safeAddress])

// Track page views – anononimized by default.
// Sensitive info, like the safe address or tx id, is always in the query string, which we DO NOT track.
useEffect(() => {
Expand Down

0 comments on commit 42633fd

Please sign in to comment.