6 changed files with 76 additions and 29 deletions
@ -1,22 +1,30 @@ |
|||||||
export const trackEvent = |
export const trackEvent = ( |
||||||
typeof process !== "undefined" && |
category: string, |
||||||
process.env?.REACT_APP_GOOGLE_ANALYTICS_ID && |
action: string, |
||||||
typeof window !== "undefined" && |
label?: string, |
||||||
window.gtag |
value?: number, |
||||||
? (category: string, action: string, label?: string, value?: number) => { |
) => { |
||||||
try { |
try { |
||||||
window.gtag("event", action, { |
// Uncomment the next line to track locally
|
||||||
event_category: category, |
// console.log("Track Event", { category, action, label, value });
|
||||||
event_label: label, |
|
||||||
value, |
if (typeof window === "undefined" || process.env.JEST_WORKER_ID) { |
||||||
}); |
return; |
||||||
} catch (error) { |
} |
||||||
console.error("error logging to ga", error); |
|
||||||
} |
if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID && window.gtag) { |
||||||
} |
window.gtag("event", action, { |
||||||
: typeof process !== "undefined" && process.env?.JEST_WORKER_ID |
event_category: category, |
||||||
? (category: string, action: string, label?: string, value?: number) => {} |
event_label: label, |
||||||
: (category: string, action: string, label?: string, value?: number) => { |
value, |
||||||
// Uncomment the next line to track locally
|
}); |
||||||
// console.log("Track Event", { category, action, label, value });
|
} |
||||||
}; |
|
||||||
|
// MATOMO event tracking _paq must be same as the one in index.html
|
||||||
|
if (window._paq) { |
||||||
|
window._paq.push(["trackEvent", category, action, label, value]); |
||||||
|
} |
||||||
|
} catch (error) { |
||||||
|
console.error("error during analytics", error); |
||||||
|
} |
||||||
|
}; |
||||||
|
|||||||
Loading…
Reference in new issue