6

I'm setting up Google Analytics for the first time and opted to use react-ga for it's simple integration into react-router and our React components. My question is, do I also need to set up the app with Google's analytics.js, or can I simply use the react-ga package? Is there any aspect of analytics.js that will be important to include?

7
  • 1
    I just took a brief look at the react-ga package, and I wouldn't recommend using it. I see zero value it adds over the analytics.js library Google Analytics provides. Using react-ga will mean you have more things to learn and you users will need to download more code. Commented Jul 26, 2016 at 22:37
  • 1
    You don't need a library to do that. The implementation is actually relatively straightforward and is described in this guide. According to the react-ga documentation, tracking SPA page changes requires basically the exact same code that guides recommends. Commented Jul 26, 2016 at 23:46
  • 1
    thanks @PhilipWalton. I see in the documentation that there is also a plugin called autotrack. Do you have any experience with that package? Commented Jul 27, 2016 at 0:10
  • 3
    Yes, I wrote it :) github.com/googleanalytics/autotrack/graphs/contributors Commented Jul 27, 2016 at 0:24
  • 1
    If all you want to use autotrack for is the SPA stuff, it may be easier to just do that manually. If you want to use some of the other plugins/functionality, I recommend it (and use it myself). Commented Jul 27, 2016 at 0:28

1 Answer 1

9

react-ga maintainer here. Thank you for your interest in react-ga.

React GA helps you to fetch Google's analytics.js and initializes analytics.js with the key that you provide to it in the ReactGA.initialize call. Hence, no you do not need to explicitly add analytics.js yourself and you can simply use react-ga package.

The value of react-ga lies in a React + GA integrated OutboundLink component and the parameter validations. As of present, React GA is a thin wrapper around the analytics.js calls but it helps you validate the parameters you pass into it and also provides a debug flag where you can see console.logs of events being sent to Google Analytics.

1
  • It fails to work in React 16 with React-router-dom, any update on when support will be available?
    – user2735832
    Commented Nov 28, 2017 at 7:54

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.