0

I am trying to enable google analytics with the help to react-ga hook.
I folloed their docs on github, I don't know why I'm not getting any data and don't know how can I debug this. I've paste this ReactGA.initialize("G-NHW4EP16PN"); code on every page but still I'm not getting anything, and also Stream configurations in my Firebase app.

import ReactGA from "react-ga";

function App() {
  useEffect(() => {
    ReactGA.initialize("G-NHW4EP16PN");
    ReactGA.pageview(window.location.pathname + window.location.search);
    console.log(window.location.pathname);
  }, []);
  return (
    <>
      <Suspense fallback={<LoadingWait src={LoadImg} />}>
        <Router>
          <Sidebar />
          <Switch>
            <Route component={Overview} path="/" exact={true} />
            <Route component={Work} path="/work" />
            <Route component={Services} path="/services" />
            <Route component={Contact} path="/contact" />
            <Route component={PageNotFound} />
          </Switch>
        </Router>
      </Suspense>
    </>
  );
}

export default App;

Chandler Bing
  • 410
  • 5
  • 25

1 Answers1

1

react-ga README

enter image description here

The initialize method takes a universal analytics gaTrackingID as its first parameter. You are sending it G-NHW4EP16PN, which not a universal analytics tracking id. I would check your account again you appear to be trying to send it a GA4 measurement id instead.

ReactGA.initialize('UA-000000-01', {
  debug: true,
  titleCase: false,
  gaOptions: {
    userId: 123
  }
});
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • How do I find that Universal tracking id, I searched for tracking id in my analytics account and I got G-NHW4EP16PN. Also I searched in my admin settings in tag installation its showing me Stream configurations in Firebase. – Chandler Bing Apr 22 '21 at 14:32
  • That's because you have a GA4 account and not an universal analytics account. You need to create a universal analytics account instead. or use the other project https://github.com/unrealmanu/ga-4-react – Linda Lawton - DaImTo Apr 22 '21 at 14:35