As much as Google touts page speed as a critical performance metric for determining the user experience and its impact on ranking, it is somewhat ironic, given that their properties are notoriously slow.
Typical Google Tag Manager Script
The typical implementation of Google Tag Manager (GTM) requires loading two scripts: one in the head and one at the end of the body. Example:
High in the <head> tag:
<!– Google Tag Manager –>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({‘gtm.start’:
new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!=’dataLayer’?’&l=’+l:”;j.async=true;j.src=
‘https://www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,’script’,’dataLayer’,’GTM-XXXXXX’);</script>
<!– End Google Tag Manager –>
After the <body> tag:
<!– Google Tag Manager (noscript) –>
<noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX”
height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
<!– End Google Tag Manager (noscript) –>
However, some companies need to load more than one GTM container and make the mistake of just adding the additional script tags. This method is effective but requires additional HTTP requests, which can negatively impact the site’s overall performance. The proper method is to load a single script and then pass multiple container IDs within it.
How to Implement Multiple Google Tag Manager Containers
Although Google recommends using a single GTM container per site to avoid complexity and conflicts, especially when managing the shared dataLayer—some organizations use multiple containers to:
Separate third-party scripts managed by partners or agencies
Maintain legacy tracking during migration
Partition environments (e.g., corporate vs. regional marketing tags)
A common but inefficient approach is to paste multiple complete GTM snippets (script + iframe) into the page for each container. While this works functionally, it introduces multiple HTTP requests, redundant execution of GTM’s base code, and potential race conditions in tag firing. This has numerous drawbacks:
Increases page weight and load time
Adds multiple calls to the GTM library
Risks of conflicting tag executions via shared dataLayer
There are two options for loading multiple GTM container IDs:
Option 1: Multiple Snippets (With Caution)
If absolutely necessary, you can load multiple GTM containers using separate snippets:
<!– GTM Container 1 –>
<script>/* Standard GTM code for GTM-XXXXXX */</script>
<noscript><iframe src=”https://martech.zone…GTM-XXXXXX…”></iframe></noscript>
<!– GTM Container 2 –>
<script>/* Standard GTM code for GTM-YYYYYY */</script>
<noscript><iframe src=”https://martech.zone…GTM-YYYYYY…”></iframe></noscript>
While this is simple, it incurs performance costs. Only use when separate teams manage containers or serve distinct business needs.
Option 2: Nested Containers via Custom HTML Tags
A more streamlined method involves loading only one primary container on the page and using a Custom HTML tag within that container to insert secondary Google Tag Manager (GTM) containers dynamically. You can accomplish this with the following steps:
Primary Container:
Implement the standard GTM snippet for your primary container.
Inside that container’s tag manager UI, create a Custom HTML tag.
Paste the full GTM snippet for the secondary container(s) into the Custom HTML.
Set Triggers Carefully
To minimize performance impact and limits cross-container interference, set a trigger for this tag so it only fires when needed—for example:
Page Path matches /partner/
Referrer contains campaign-abc
Custom Event = loadSecondaryGTM
Manage DataLayer Conflicts
If both containers write to the same dataLayer, you risk overwriting or misfiring tags. You can isolate data by:
Scoping variable names
Using dataLayer.push() only when needed
Monitoring in Preview Mode for collisions
You can also change the data layer name (l in the script above) if your containers are entirely separate.
Pros
Centralizes GTM logic in one place
Avoids loading multiple GTM libraries upfront
Can delay or conditionally load secondary containers
Cons
Requires precise trigger logic
May complicate dataLayer management
Must be thoroughly tested to prevent conflicts
Can You Load Multiple Containers in a Single Google Tag Manager Call?
Thanks to reader, James Carter, I’ve updated this article. He accurately pointed out that you cannot load multiple GTM containers by combining their IDs in one script or iframe URL. GTM does not support a comma-delimited list of IDs in its JavaScript source path. Any attempt to concatenate multiple IDs in a single <script> or <iframe> source will result in invalid requests or missing containers.
Performance Considerations
Regardless of how you implement multiple GTM containers, remember:
Each container still loads its full tag configuration.
Each tag inside each container may fire its own scripts or network requests.
Redundant containers slow down Time to Interactive (TTI) and Largest Contentful Paint (LCP).
Best Practice: If possible, consolidate all tags into a single container and use GTM’s built-in permissions or workspaces to manage organizational complexity.
©2025 DK New Media, LLC, All rights reserved | Disclosure
Originally Published on Martech Zone: How To Load Multiple Google Tag Manager Container IDs