Search code examples
containersgoogle-tag-managerpublishinglaunchtagging

Google Tag Manager Container- Dev. Website to Published Website Advice


I just wanted to make sure I would be approaching this problem correctly when it comes time to publish our website next week that has had a few pages added onto it. Any advice is greatly appreciated.

So, as of right now we have an original container (Container 1) in Google Tag Manager, it has a few tags set up and working, great. Last week, I created a new container in GTM (Container 2) and have been using that to test our dev. website. Adding a few tags to the new pages of our website so I am ready to add them to our actual published website once it goes live.

When I created Container 2 I sent the GTM code to the developer and he put it into the header of the dev. website My question is.. when we publish the dev. website are we going to need to remove that code from the header and replace it with Container 1's code that way we are operating on the existing tags and I only have to replicate the few tags I made in Container 2?

Clarification: I want to keep my tags from Container 1 and use this container as the website still needs all these tags, I was just creating tags for additional pages to the website, it has otherwise remained the same.


Solution

    1. Generally, you're not supposed to use a separate GTM container for lowers. GTM has its own environments made exactly for this case. You can just make a lower environment in GTM, get code for it and install it on your site's lower env. Here's more on it: https://support.google.com/tagmanager/answer/6311518?hl=en
    2. Most of sites that use GTM, would use the same container and the same GTM env on prod and on lowers. They would just use the preview function in GTM to make sure everything's as expected and publish to the only env they have. And it works pretty fine in vast majority of cases.
    3. In rare cases, it can be justified to have different GTM containers for dev and prod. But when you do this, you will have to keep both containers equivalent and your publishing to prod now would have to involve moving changes from one container to another, which is not a typical way of using GTM, so GTM itself doesn't have capabilities to do that elegantly. You would have to either export and import the whole workspace with changes to the prod container, or use this handy extension: https://chrome.google.com/webstore/detail/gtm-copy-paste/mhhidgiahbopjapanmbflpkcecpciffa?hl=en

    Now that we've overviewed how things should be done, let's get to your question at hand.

    Your questions is, basically, asking whether your developers are going to replace container 1 with container 2 when pushing the lowers to prod. Ask them. But generally, it's better to have three things in place:

    1. Have developers never push the GTM code from dev to prod, maintaining different GTM snippets on dev and prod.

    2. Have a universal container-agnostic tracking logic in your containers, so that even if the developers push the dev container to prod, your tracking is still perfect and all the events are going to the production GA rather than dev GA.

    3. Have a universal, container-agnostic logic that console.warns a GTM message if it detects that the dev container is being used on prod.

    There.

    In short, the easiest thing for you is to keep container 1 on prod and 2 on dev always, but maintain parity between them and move changes from 2 to 1 every time you're done with your work. That's the expedient option.

    The proper thing to do is to remove container 2 completely, create an environment in container 1, have your lower env container 1 code deployed to dev, notify the devs that that container is for dev only and make sure your code there is universal.