This website uses cookies to improve your experience and deliver relevant information.

on Monday, 12 June 2017

Setting up Google Tag Manager (GTM) environments for tag testing

I often have moments in the office where I am so excited by a new feature that I start clapping excitedly and pointing at the screen - this was definitely one of them! For some time we had been trying to figure out how to reliably test our marketing tags between different environments - development, demo and production - without accidentally putting tags in the wrong place or leaving debug mode enabled.

We used to achieve this with different containers in Google Tag Manager for each environment or using the 'preview' mode, which was very cumbersome - so the day back in November 2015 when Google launched its 'environments' feature in Google Tag Manager was most definitely a happy clappy day!

Environments are Google Tag Manager's way of allowing you to test out tags in a development area prior to launching them to your live site.  Anybody who has ever pushed a new tag without testing and caused some epic javascript conflict resulting in owing the development team beer will totally appreciate how useful this feature is!

In essence, you simply set up your environments within the GTM settings, and then copy the snippet for each environment - or you can use the 'share preview' link for each environment if that isn't possible to do. 

Once you have the environments set up, when you publish changes to a container, you are asked which environment you wish to publish your changes into - et voila!

Setting up environments

Log into your Google Tag Manager account and find your container.  Open up the relevant container, and click on 'Admin' on the top menu bar.  In the middle settings box toward the bottom you will find 'environments'.  Click on this to open up your environments.

google tag manager environment settings

Click on 'New' to create a new environment, and complete the fields as appropriate to your environment.  You may wish to enable debugging on your development area - it's optional.

google tag manager create environment 

Once you create the environment, you will have a popup explaining that you can either use the 'share preview' feature to test the tags in this environment, or you can add the snippet to your website.  Click to move forward, after which you will be presented with the list of environments.  It's worth mentioning here that you can't edit the default environments - only your custom environments.

google tag manager environments

If you click on the 'Actions' drop-down arrow for the environment you just created, there is an option to copy the container snippet - this allows you to embed the environment container within the development environment of your website.

google tag manager get snippet

Setting up multiple environments

There is every possibility that you might need to set up multiple environments - for example, we have development, demo, and production environments for most projects.  Simply repeat the process above as many times as you need to generate the separate environments!

Working with environments

Once your environments are set up and running, each time you publish a change in a container you will be prompted to select which environment your changes should be published into.  Take this step slowly and make sure you check every time you deploy changes, which environment you are pushing them into!

google tag manager publish to environment

Made a mistake?  

You can always roll back to your previous container version, by clicking on 'Versions' in the top menu, and identifying the previous version that you need to roll back to.

google tag manager rolling back

Simply select 'Publish to' and choose the environment that you need to roll back.  Once this is completed, you can repeat the original deployment to the correct environment via Actions>Publish To on the latest environment, and all should be well with the world!

google tag manager after roll back

 

Need Marketing or SEO support for your project? Work with the experts today!

Virya Group provides a range of solutions to your technology needs