analytics.ts 855 B

12345678910111213141516171819202122
  1. export const trackEvent =
  2. typeof process !== "undefined" &&
  3. process.env?.REACT_APP_GOOGLE_ANALYTICS_ID &&
  4. typeof window !== "undefined" &&
  5. window.gtag
  6. ? (category: string, action: string, label?: string, value?: number) => {
  7. try {
  8. window.gtag("event", action, {
  9. event_category: category,
  10. event_label: label,
  11. value,
  12. });
  13. } catch (error) {
  14. console.error("error logging to ga", error);
  15. }
  16. }
  17. : typeof process !== "undefined" && process.env?.JEST_WORKER_ID
  18. ? (category: string, action: string, label?: string, value?: number) => {}
  19. : (category: string, action: string, label?: string, value?: number) => {
  20. // Uncomment the next line to track locally
  21. // console.log("Track Event", { category, action, label, value });
  22. };