Learn business growth with Google Analytics 4 Forums Google Analytics 4 Unresolved Issue: Retained iframes in DOM with GTM Reply To: Unresolved Issue: Retained iframes in DOM with GTM

  • John

    23 June 2023 at 9:12 am

    It does seem like your application is experiencing a memory leak. Generally, elements inserted into the DOM should not persist across navigation in a Single Page Application (SPA) like Angular. The view should be completely destroyed and recreated when navigating to a new route. Based on your explanation, it might indeed, be the behavior of the Custom HTML Tag that adds the script element and the DoubleClick Floodlight iFrame to the DOM persistently. The growing heap size with each navigation would be indicative of this.

    The natural behavior of Google Tag Manager (GTM) is not this. It’s designed to make the management of such script tags easier, not to insert them into the DOM and leave them there. It’s possible that it’s due to the Custom HTML Tag or how DoubleClick Floodlight is configured in GTM. So, you may want to investigate the configuration of these tasks.

    Creating a cleanup tag could be a viable workaround, but it could lead to a higher complexity of your tag setup in GTM and potentially an increased possibility of bugs. A better approach might be to work on the root of the problem and change how these total elements are injected into the DOM, and inspect the behavior of the Custom HTML tag and DoubleClick Floodlight within GTM.

    If that doesn’t work, then you probably need to check your Angular application if it’s correctly destroying and re-creating your views on navigation. You might want to consider employing some sort of manual cleanup via Javascript within your application, although this should be considered as a last resort due to its complexity.

    For further debugging, I would recommend using the Google Tag Assistant plugin, as it can provide valuable insight into when and how your tags are firing. Hope this gives you some insight and guidance to tackle the memory leak issue.