How to fix duplicate event collection on Single Page Applications.

Jun 16, 2023 | Debugging, Digital Analytics, GA4, GA4 - Events


When can an event on a Single Page Application be collected more than once in Google Analytics? 

This behaviour can be observed in different situations and trying to describe all the possibilities is fairly difficult but most of the time you’ll experience duplicate event collection :
  • Because of the conditional rendering of your Google Analytics tag after the user accepts the consent to be tracked using a Consent Management Platform ( Liveramp / UserCentrics / etc.. )
  • The JS code related to the events is inside some sort of loop which runs more than once
  • When using a Tag Management System ( GTM / Tealium ) you can incur in duplicate event tracking when the portion of JS code responsible for the events runs more than once. 

How to fix Google analytics duplicate event collection on Single Page Applications ? 

If you’re using a Tag Management System ( GTM / Tealium ) you should have available some option for which you can prevent the code from firing more than once.  But sometimes there could be other factors that could still let the event be collected twice or for some reason you cannot run the extension only one time.  If you’re in this situation you can try to set a counter to prevent the event from firing if this counter has been already triggered.  Depending on the implementation you should know that you can use different areas to store a counter: 
  • Local Storage
  • Session Storage
  • JS variable on the global object ( window)
  • Built-in variable in the Tag Management System
Here is a hint : Don’t forget to put the counter at zero when moving from a SPA to another website area outside the SPA or in some cases also when moving around in the same SPA otherwise you’ll end up creating unwanted side effects As always in these situations, there is no solution applicable to all the cases out there. If you’re struggling with these or other topics feel free to contact us and we’ll help you with an AD-HOC solution for your needs.

Related posts

Tealium Crash Course

Tealium Crash Course

What will be covered in the course What is Tealium 2 Real World scenarios: 2 Google ADS tag implementations. </strong >While going through this scenario we’ll learn: How to request Permissions...

read more