tldraw/utils/gtag.ts

27 lines
557 B
TypeScript
Raw Normal View History

2021-06-19 09:00:44 +00:00
export const GA_TRACKING_ID = process.env.GA_MEASUREMENT_ID
type GTagEvent = {
action: string
category: string
label: string
value: number
}
2021-06-21 21:35:28 +00:00
export const pageview = (url: URL): void => {
2021-06-24 12:34:43 +00:00
if ('gtag' in window) {
;(window as any)?.gtag('config', GA_TRACKING_ID, {
page_path: url,
})
}
2021-06-19 09:00:44 +00:00
}
2021-06-21 21:35:28 +00:00
export const event = ({ action, category, label, value }: GTagEvent): void => {
2021-06-24 12:34:43 +00:00
if ('gtag' in window) {
;(window as any)?.gtag('event', action, {
event_category: category,
event_label: label,
value: value,
})
}
2021-06-19 09:00:44 +00:00
}