ReactGA not working for G type tracking Id
Asked Answered
P

3

6

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() {
    ReactGA.initialize("G-QBQXxxxxx");
    ReactGA.pageview("/")
  }

Anything wrong in my implementation ?

Pineal answered 1/6, 2020 at 15:49 Comment(0)
M
12

Based on react-ga docs, it is designed to work with Universal Analytics which was the latest version of Google Analytics until Oct 14, 2020. Since then, GA-4 is the default property type in Google Analytics. You need to create a property of type Universal Analytics. To do so, go to Google Analytics Home page and go to Admin.

enter image description here

Select the Account that you want to add a Property to and click on Create Property.

enter image description here

Now you proceed to Property setup page. (Also you could have created a new Account and after setting its name in the second step you would have seen Property Setup). Then click on Show advanced options.

enter image description here

Enable Create a Universal Analytics property and select one of the available options. If you select Create both a Google Analytics 4 and a Universal Analytics property, you will have two different properties one having a MEASUREMENT ID like GA-XXXXXXXXXX and another having a Tracking ID like UA-XXXXXXXXXX. Use the Tracking ID instead of MEASUREMENT ID.

enter image description here

Maroon answered 15/11, 2020 at 11:34 Comment(2)
what is the advantage of choosing both options(Google Analytics 4 and Universal Analytics property)?Nonobservance
Then you can track your app stats using both GA4 and UAT. I mean you can use both Measurement ID (starting with "G-") and Tracking ID (starting with "UA-") for the same app. Some libraries may require "G-" while some others require "UA-". When you have both of them in your Google Analytics account for the same app, you'll have both options in your hand.Maroon
S
2

The Universal Analytics id its going to be desappear in 2023 July 1° and the react-ga is outdated, because only works with UA code.

For this reason, you can use react-ga4, and you can use the Measurement ID (which begins with "G-")

Schoolboy answered 25/9, 2022 at 15:24 Comment(0)
G
1

Instead of using the Measurement ID (which begins with "G-"), set up a Universal Analytics ("Web") property (Universal Analytics properties have views instead of data streams), you have a Tracking ID (which begins with "UA-"), and then

import ReactGA from "react-ga";
componentDidMount() {
    ReactGA.initialize("UA-XXXXXXXX");
    ReactGA.pageview("/")
  }

It works just fine

Ganges answered 29/10, 2020 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.