analytics.ts 623 B

12345678910111213141516171819202122232425
  1. import getConfig from "next/config";
  2. import ReactGA from "react-ga";
  3. const { publicRuntimeConfig } = getConfig();
  4. export const initGA = () => {
  5. ReactGA.initialize(publicRuntimeConfig.GOOGLE_ANALYTICS);
  6. };
  7. export const logPageView = () => {
  8. ReactGA.set({ page: window.location.pathname });
  9. ReactGA.pageview(window.location.pathname);
  10. };
  11. export const logEvent = (category = "", action = "") => {
  12. if (category && action) {
  13. ReactGA.event({ category, action });
  14. }
  15. };
  16. export const logException = (description = "", fatal = false) => {
  17. if (description) {
  18. ReactGA.exception({ description, fatal });
  19. }
  20. };