-
Unresolved Issue: Retained iframes in DOM with GTM
Hey there, I’ve been tinkering with an Angular single page app and I’ve been using GTM with it. Every time I switch between pages, I have a Page-View event that’s triggered by
window.dataLayer.push(obj)
.obj
here means the whole object, if you’re unsure.Anyways, things get a bit more complicated with GTM. I have these two triggers, one that adds a Custom HTML element (a script element actually), and it triggers another
dataLayer.push
but with a simple object just to signal a new page view and the previous referer. With the other one, an iframe of type DoubleClick Floodlight is added to the DOM to keep tabs on certain behaviors for a short lifespan.From my understanding, these events are supposed to just pop up once in the DOM and then just sort of disappear. However, every new page view adds two more elements to the DOM (the script element + the iframe). I’ve been noticing this weird accumulation; every new page view just adds to the js heap size, which I think is the reason my Chrome DevTools is depicting a significant memory leak.
Even though the
dataLayer
pops the oldest event once it reaches 300 events, this issue is still concerning me. What I’m trying understand is that if this is something that is to be expected with GTM? Or is it me who’s missing something in the larger picture with GTM?Do you think I would need to create a cleanup tag that will trigger once all elements have been inserted into the DOM? Or even go a step further and have a system where I track and remove it from within my application itself?
To be honest, I’m still struggling to fully comprehend this issue and I would really appreciate it if anyone can throw some light into it.
I haven’t actually tried anything to fix this yet. I have only been researching on stackoverflow and other resources including articles, videos and documents. I hope to find some seasoned advice from this community to guide me on what I should be doing next. Thanks in advance!
Log in to reply.