analytics.js 589 B

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