Questions tagged [react-ga]
67 questions
88
votes
8 answers
Adding Google Analytics to React
I am trying to add Google Analytics to a React Web Application.
I know how to do it in HTML/CSS/JS sites and I have integrated it in an AngularJS app too. But, I'm not quite sure how to go about it when it comes to react.
With HTML/CSS/JS, I had…

Raj
- 3,637
- 8
- 29
- 52
37
votes
10 answers
Google Analytics 4 with React
I've been trying to use react-ga package with google analytics 4 in my app. The measurement id doesn't work with it and there is no tracking code in google analytics 4 I can use. Please, I need help!
import ReactGA from 'react-ga';
const trackingId…

iMyke
- 573
- 1
- 7
- 10
16
votes
2 answers
ReactGA.initialize must be called first
I am getting the following warning multiple times (for multiple pages) despite me initializing at the root of my app. This makes me wonder if google analytics is even working properly?
[react-ga] ReactGA.initialize must be called first or…

Matt Strom
- 698
- 1
- 4
- 23
9
votes
7 answers
How to use Google Analytics with React?
In my react app I have some pages:
Main
Service
Contact
Profile (private)
etc..
I need to track users activity with Google Analytics. I googled react-ga and it's just fine. But with this library I have to initialize my GA on every route I use.…

Nastro
- 1,719
- 7
- 21
- 40
9
votes
1 answer
Has anyone been successful in implementing google optimize in a SPA React App?
I am fairly new to the Google Analytics Suite and am currently trying to integrate Google Optimize for A/B testing in a react app.
I have gotten to the point where the variant changes display on the desired web page, but only in Preview mode, and am…

rh0delta
- 129
- 1
- 8
6
votes
3 answers
ReactGA not working for G type tracking Id
I am trying to implement google analytics in my reaact application. But does give any page hit in analytics dashboard.
Here is the implementation:
In App.js:
import ReactGA from "react-ga";
componentDidMount() {
…

Nishant_061
- 87
- 1
- 7
5
votes
1 answer
Unable to track time spent on React web app with Google Analytics
I have built a React web app and I would like to track the users time spent on my website using Google Analytics.
Currently I am using react-ga (https://github.com/react-ga/react-ga) as a tool to bind the Google Analytics with React. I have…

Eric Lee
- 103
- 1
- 6
4
votes
1 answer
How to migrate 'displayfeatures' and 'ec' plugins requirements from react-ga to react-ga4
Because of the upcoming GA4, we will start using react-ga4 instead of react-ga. And we have these lines in our code for the GA initialization from the react-ga.
ReactGA.plugin.require('displayfeatures');
ReactGA.plugin.require('ec');
I couldn't…

sbb
- 529
- 3
- 25
4
votes
3 answers
CORS Error when running a pageView for ReactGA
I am trying to add React-GA to a react web app and have followed the documentation by adding it to index.js:
import ReactGA from 'react-ga';
ReactGA.initialize('MY_ID');
ReactGA.pageview(window.location.pathname + window.location.search);
However,…

Paradox
- 4,602
- 12
- 44
- 88
4
votes
3 answers
Where to put User ID in a GA tracking flow?
I am using React-GA, and it works as expected, but I have a requirement to put user email in event tracking:
I see this in the example:
ReactGA.event({
category: 'Editing',
action: 'Deleted Component',
label: 'Game Widget'
});
I have a email…

Sergei Basharov
- 51,276
- 73
- 200
- 335
4
votes
1 answer
React Router NavLink not triggering history.listen() function
I am trying to implement Google Analytics using the react-ga library which needs to fire whenever the route changes. I have the following setup in App.js:
import createBrowserHistory from 'history/createBrowserHistory';
...
const history =…

Troy Carlson
- 2,965
- 19
- 26
3
votes
1 answer
React-GA events are firing off in debug console but not showing up in GA
I have been trying to make this work for a few days, and nothing is working. The events are simply not being captured no matter what I do.
I import ReactGA at the top
import ReactGA from "react-ga";
I initialize it after…

0rando
- 135
- 3
- 9
3
votes
0 answers
Google Analytics eCommerce with ReactGA
I am using the React-GA library for sending analytics to Google Analytics.
I've managed to set it up for pageviews and event tracking, but I'd also like it to work with eCommerce. I am fairly new to this, but I've figured out this:
I need to…

Martin Nordström
- 5,779
- 11
- 30
- 64
3
votes
0 answers
ReactGa initialize when track id is being fetch asynchronously
i'm using react-ga from track my react app using google analytics. I'm fetching the tracking id through an API call and is returned after approximately 4 seconds. My function is this:
const withTracker = (WrappedComponent, options = {}) => {
const…

RamAlx
- 6,976
- 23
- 58
- 106
3
votes
0 answers
Use react-ga for tracking the visitor of your home page
i need to integrate my react application using google analytics. I found the react-ga library which looks reliable and "easy" to use. But i didn't use google analytics in the past and i'm having some dificulties. First of all i use the withTracker…

RamAlx
- 6,976
- 23
- 58
- 106