2021-09-04 12:02:13 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
export const GA_TRACKING_ID = process.env.GA_MEASUREMENT_ID
|
|
|
|
|
|
|
|
type GTagEvent = {
|
|
|
|
action: string
|
|
|
|
category: string
|
|
|
|
label: string
|
|
|
|
value: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export const pageview = (url: URL): void => {
|
|
|
|
if ('gtag' in window) {
|
2021-09-22 12:17:52 +00:00
|
|
|
const win = window as any
|
|
|
|
win?.gtag('config', GA_TRACKING_ID, {
|
2021-09-04 12:02:13 +00:00
|
|
|
page_path: url,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const event = ({ action, category, label, value }: GTagEvent): void => {
|
|
|
|
if ('gtag' in window) {
|
2021-09-22 12:17:52 +00:00
|
|
|
const win = window as any
|
|
|
|
win?.gtag('event', action, {
|
2021-09-04 12:02:13 +00:00
|
|
|
event_category: category,
|
|
|
|
event_label: label,
|
|
|
|
value: value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|