|
|
@ -3,29 +3,11 @@ export {}; |
|
|
|
declare global { |
|
|
|
declare global { |
|
|
|
interface Window { |
|
|
|
interface Window { |
|
|
|
gtag: any; |
|
|
|
gtag: any; |
|
|
|
fireEvent: (props: EventType) => void; |
|
|
|
fireEvent: (props: GAEventType) => void; |
|
|
|
firePageView: (url: string) => void; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
export type GAEventType = { |
|
|
|
* Tracks the page view on google analytics |
|
|
|
|
|
|
|
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
|
|
|
|
|
|
* @param url URL to track |
|
|
|
|
|
|
|
* @returns void |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
window.firePageView = (url: string) => { |
|
|
|
|
|
|
|
if (!window.gtag) { |
|
|
|
|
|
|
|
console.warn('Missing GTAG - Analytics disabled'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.gtag('config', 'UA-139582634-1', { |
|
|
|
|
|
|
|
page_path: url, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type EventType = { |
|
|
|
|
|
|
|
action: string; |
|
|
|
action: string; |
|
|
|
category: string; |
|
|
|
category: string; |
|
|
|
label?: string; |
|
|
|
label?: string; |
|
|
@ -38,7 +20,7 @@ type EventType = { |
|
|
|
* @param props Event properties |
|
|
|
* @param props Event properties |
|
|
|
* @returns void |
|
|
|
* @returns void |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
window.fireEvent = (props: EventType) => { |
|
|
|
window.fireEvent = (props: GAEventType) => { |
|
|
|
const { action, category, label, value } = props; |
|
|
|
const { action, category, label, value } = props; |
|
|
|
if (!window.gtag) { |
|
|
|
if (!window.gtag) { |
|
|
|
console.warn('Missing GTAG - Analytics disabled'); |
|
|
|
console.warn('Missing GTAG - Analytics disabled'); |
|
|
|