analytics.ts 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import getConfig from "next/config";
  2. import ReactGA from "react-ga";
  3. import * as Sentry from '@sentry/react';
  4. import { Integrations } from '@sentry/apm';
  5. const { publicRuntimeConfig } = getConfig();
  6. export const initGA = () => {
  7. ReactGA.initialize(publicRuntimeConfig.GOOGLE_ANALYTICS);
  8. };
  9. export const logPageView = () => {
  10. ReactGA.set({ page: window.location.pathname });
  11. ReactGA.pageview(window.location.pathname);
  12. };
  13. export const initSentry = () => {
  14. if (publicRuntimeConfig.SENTRY_PUBLIC_DSN) {
  15. Sentry.init({
  16. dsn: publicRuntimeConfig.SENTRY_PUBLIC_DSN,
  17. environment: process.env.NODE_ENV,
  18. integrations: [
  19. new Integrations.Tracing(),
  20. ],
  21. tracesSampleRate: 1.0,
  22. });
  23. };
  24. };
  25. export const logEvent = (category = "", action = "") => {
  26. if (category && action) {
  27. ReactGA.event({ category, action });
  28. }
  29. };
  30. export const logException = (description = "", fatal = false) => {
  31. if (description) {
  32. ReactGA.exception({ description, fatal });
  33. }
  34. };