1

I want to implement Google Analytics on my react application and I have set it up using react-ga module.

import ReactGA from "react-ga";
...
ReactGA.initialize('analytics-code-here');

const App = () => {

    useEffect(() => {
        ReactGA.set({ page: window.location.pathname + window.location.search});
        ReactGA.pageview(window.location.pathname + window.location.search)
    }, [])

    return (
       ...
    );

I have set it up two days ago, but there is no data sent to my analytics account.
How could I recieve data into Google Analytics?

Amir
  • 473
  • 2
  • 11
  • 24

1 Answers1

0

For pageview you don't need to use set command, just use these lines to initializing GA and tracking pageviews:

import ReactGA from 'react-ga';
ReactGA.initialize('UA-000000-01');
ReactGA.pageview(window.location.pathname + window.location.search);

https://github.com/react-ga/react-ga

Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
  • thanks you. I've removed it, but it not showing anything in my analytics account – Amir Aug 23 '20 at 09:16
  • UA code is right? Do you get some errors in console/log? – Michele Pisani Aug 23 '20 at 10:04
  • I have set debug to true in the ReactGA and it just outputs the same function and some variables and their values but no errors – Amir Aug 23 '20 at 11:58
  • yes, it does. I tried both when I make a web only it starts with UA- and I tried it also as web + app it doesn't but both didn't show anything – Amir Aug 23 '20 at 13:05
  • What version of react? See this post: https://stackoverflow.com/questions/49398355/google-analytics-on-react-app-doesnt-work/50289783 – Michele Pisani Aug 23 '20 at 13:29