ga-4-react icon indicating copy to clipboard operation
ga-4-react copied to clipboard

is "Error: GA4 is being initialized" expected behaviour?

Open gurnoora21 opened this issue 3 years ago • 4 comments

Screen Shot 2021-06-15 at 9 32 13 AM

Hey,

Is "GA4 is being initialized" an expected error within console on any page using this package. Looking at the js code for the package, it seems like the error is thrown while the initialization code is run?

gurnoora21 avatar Jun 15 '21 15:06 gurnoora21

I was able to get it to work fine. Are you initializing the class two times?

bert0RM avatar Jul 25 '21 03:07 bert0RM

I get this as well, using the snippet of code given in the docs

ga4react.initialize().then((ga4) => {
  ga4.pageview('path')
  ga4.gtag('event','pageview','path') // or your custom gtag event
},(err) => {
  console.error(err)
})

Is there a way to call ga4.pageview() a second time for subsequent page views (ie route changes w react router) without initializing again?

RM-Eric avatar Feb 11 '22 17:02 RM-Eric

you can keep the result of the initialization promise in a variable, without having to initialize again

I hope I was helpful, a greeting

unrealmanu avatar Feb 11 '22 17:02 unrealmanu

Thanks, that worked.

RM-Eric avatar Feb 11 '22 21:02 RM-Eric