Reply
Highlighted
Occasional Visitor
Posts: 1
Registered: ‎04-18-2017

react route pagview to populate url in google analytics

I have a SPA react based app and I trigger pageview upon navigation through the app when url changes. I have added the GA tag. GA pageview locaiton field is always populated with the value of the url of the first page on which the user lands and not the subsequent urls. How may I go about changing the location?

Reply
0 Kudos
Tealium Employee
Posts: 19
Registered: ‎09-01-2015

Re: react route pagview to populate url in google analytics

[ Edited ]

@momen,

 

You can overwrite the location parameter for the Google call by mapping a variable to the "location" destination in your Google Analytics tag mapping toolbox. This variable should be dynamically updated with the value in your utag.link or utag.view call for all subsequent (not initial pageview) events for your REACT setup. Also, you will want to make sure that you have the "clear vars" setting within the tag's configurations set to "on" to make sure that all variables set with the "SET.xxxx" method from Google are cleared out. 

 

Hope that helps!

 

Chris

Visitor
Posts: 18
Registered: ‎03-09-2016

Re: react route pagview to populate url in google analytics

[ Edited ]

@momen, as we are using Tealium on a React based website as well, I want to advise against setting the location parameter but instead to set the page parameter on every view. This is also the official advise from Google (https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications#do...).

 

The reason for this is that setting the location parameter risks to lose referral information, which may cause a session restart in Google Analytics. Simon Ahavas blog has some background information on this topic (https://www.simoahava.com/gtm-tips/fix-rogue-referral-problem-single-page-sites/).