0
Fixed

Injector not injecting on sites with GTM already enabled.

James Cottrill 6 months ago in Tag Manager updated 6 months ago 4

I'm currently not able to inject onto any sites with GTM already enabled


It looks like the fix to Julius' bug has created a bug in whilst injecting on sites with GTM already enabled.

Answer

Answer
Fixed

This was really stupid on my part - I did all the tests to make sure it was working when there was no container and didn't re-check the other scenario! :(
Fixed for next release.
There's another annoying issue so I will likely release a hot fix today.

GOOD, I'M SATISFIED
Satisfaction mark by James Cottrill 6 months ago

Managed to submit this before I had finished typing! 

This is the error that I get when trying to inject.

The script looks like it's trying to iterate through the window rather than the dataLayer.

i is also used as the variable for the container Id, so w[l][i] passes the logic but overwrites the container Id. I've got it working with

(function(w,d,s,l,i,a){w[l]=w[l]||[];var t=!1;for(a in w[l])if(w[l][a]['event']&&w[l][a]['event']==='gtm.js'){t=true;break}if(!t)w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});const f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=!0;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f)})(window,document,'script','dataLayer','GTM-XXXXXX')

Hope that all makes sense, it did in my head!

Answer
Fixed

This was really stupid on my part - I did all the tests to make sure it was working when there was no container and didn't re-check the other scenario! :(
Fixed for next release.
There's another annoying issue so I will likely release a hot fix today.

Thanks Stéphane, much appreciated!