mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-19 23:37:25 -05:00
20 lines
596 B
TypeScript
20 lines
596 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 ?? [])])
|
|
}
|