Kemen Paulos Plaza Kemen Paulos Plaza - 10 months ago 75
Ajax Question

GTM as Singleton (Google Tag Manager)


There is any way to execute GTM as a Singleton? , i need only a single execution of GTM.

To add some more context, my aplication is a single page aplications (without uri change), and the content is loaded via Ajax, but the entire HTML changes with every interaction. When the content changes the entire code is reloaded, reexecuting the GTM code getting 2 instances of GTM.

Any ideas to fix the problem?

Answer Source

At the end i used a javascript variable and check it before execute the gtm main snippet, just a basic workaround

if(typeof gtm_on == "undefined"){
<!-- Google Tag Manager -->
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],