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?
1 Answer
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.log
s of events being sent to Google Analytics.
-
It fails to work in React 16 with React-router-dom, any update on when support will be available?– user2735832Commented Nov 28, 2017 at 7:54
react-ga
package, and I wouldn't recommend using it. I see zero value it adds over the analytics.js library Google Analytics provides. Usingreact-ga
will mean you have more things to learn and you users will need to download more code.react-ga
documentation, tracking SPA page changes requires basically the exact same code that guides recommends.