You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
831 B

export function trackPageview(url: string) {
const _window = window as typeof window & { gtag: any }
try {
_window.gtag("config", process.env.GA_TRACKING_ID, {
page_location: url,
page_title: document.title,
})
} catch (err) {
console.error("Failed sending metrics", err)
}
}
type TrackEventOptions = {
action: any
category: string
label: string
value: string
}
export function trackEvent(options: TrackEventOptions) {
const { action, category, label, value } = options
const _window = window as typeof window & { gtag: any }
try {
_window.gtag("event", action, {
event_category: category,
event_label: label,
value,
})
} catch (err) {
console.error("Failed sending metrics", err)
}
}