Search code examples
javascriptreactjsgoogle-analyticsreact-ga

react-ga - simplest Google Analytics set-up on React - no response


I'm trying to set up Google Analytics on my React app but I can't get anything working.

I've followed the documentation and am running the following code included in my app.js:

import ReactGA from 'react-ga'
  ...
useEffect(() => {
    ReactGA.initialize(process.env.REACT_APP_GOOGLE_ANALYTICS)
    ReactGA.pageview('/')
    ReactGA.pageview(window.location.pathname + window.location.search);
  }, [])

(I've saved my Tracking ID into my .env file, which I copied from my analytics.google console)

I'm running my app from localhost:3000 but nothing is being sent via my network tab in developer tools in Chrome (I assume that's where you would see the data being sent back to Google Analytics). I've also tried following the "Demo Code" here: https://github.com/react-ga/react-ga

Nothing changes on my Google Analytics console and I don't see anything happening in my developer tools.

Can someone please tell me how to get started here?


Solution

  • OK so I had an ad blocker running in my Chrome extensions and it was killing Google Analytics. There was no error message in my developer tools so there was no way of working it out, only for the fact I saw this post in the react-ga Issues page: https://github.com/react-ga/react-ga/issues/449

    Hope this saves someone else the time!