Files
Compass/web/hooks/use-tracking.ts
Martin Braquet ba9b3cfb06 Add pretty formatting (#29)
* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
2026-02-20 17:32:27 +01:00

20 lines
597 B
TypeScript

import {useEffect} from 'react'
import {track} from 'web/lib/service/analytics'
import {inIframe} from './use-is-iframe'
import {useIsAuthorized, useUser} from './use-user'
export const useTracking = (
eventName: string,
eventProperties?: any,
excludeIframe?: boolean,
extraDeps?: any[],
) => {
const isAuthed = useIsAuthorized()
const user = useUser()
useEffect(() => {
if (isAuthed === undefined) return
if (excludeIframe && inIframe()) return
track(eventName, {...eventProperties, userId: user?.id})
}, [isAuthed, eventName, excludeIframe, ...(extraDeps ?? [])])
}