React-ga: Multiple react GA instances with react SSR after opening new tab

Created on 26 Jul 2018  路  6Comments  路  Source: react-ga/react-ga

Not sure if this has been flagged up before but we noticed that when a new tab is opened, within that tab it causes a new GA tag to created inside whenever user navigates to a new page or click on an action.

I believe the normal behaviour is that there should only be one instance of GA? This causes some inaccurate data within google analytics dashboard but I am not sure if this is an issue with our implementation, or with react-ga.

Appreciate if anyone has experienced this before can shed some light.

screen shot 2018-07-20 at 10 06 41 am

Most helpful comment

I fixed it with:

if (!window.ga) {
    ReactGA.initialize(...)
}

All 6 comments

I fixed it with:

if (!window.ga) {
    ReactGA.initialize(...)
}

I literally came here for this reason. Turns out I'm an idiot and was calling it on render(). Thanks for your fix @Drapegnik

@Drapegnik, what does it fix exactly? What kind of issue can you get from not setting up react-ga the way you do?

@amangeot I prevent multiple ReactGA instances on the page by calling ReactGA.initialize only once

Thank you for your quick reply @Drapegnik

I currently have a tracking issue. I have a widget hosted in iframes on other websites showing content from example.com/embed. When initializing my react app from these /embed urls, a specific tracking ID is used. The problem is that my main website tracks both website and widget sessions, even though it's initialized with a different tracking ID. The widget tracking ID accurately tracks only those widget sessions.

Do you know what could messup the tracking?

I was wondering if it could have anything to do with GA initialization settings as you mentioned

Oh my issue came from somewhere else!

In case somebody reads this, my issue was that Google Tag Manager was loaded in our HTML template, and GTM was responsible for loading our main tracking ID for widget sessions, therefore widget sessions being tracked by both IDs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

khmelevskii picture khmelevskii  路  5Comments

amcinerneynewf picture amcinerneynewf  路  4Comments

kenjoe picture kenjoe  路  4Comments

velchevski picture velchevski  路  3Comments

donaldpipowitch picture donaldpipowitch  路  4Comments