Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: attach safe address to analytics events #2524

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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