analytics.js 532 B

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