In this article, we will look at how to configure your production website, pre-production and test environments from a single Google Tag Manager.

We will learn how to create a new version of your Tag Manager workspace, test on Staging and deploy to Production.

Indeed, we will speak about Quality Assurance with GTM.

If you are here you might know that most businesses and large entreprises have an established release process of changes on their website that involved several deployment environments.

A typical setup is made of:

  • Test environment where the development team tests the new features for the website.
  • Staging environment replicating your production website where final users can run acceptance tests (UAT).
  • Production or Live environment for your public website.

Each new version of the website is be tested from one environment to another until it is fully validated and put online.

Familiar with this process? But do you know…. How to test your marketing tags with Google Tag Manager?

Google Tag Manager and the “environment” feature will allow you to test your marketing tags before deploying them in production.

At the end of this tutorial, you will

  • Understand how to setup a Google Tag Manager staging environment and development environments.
  • Have an advanced configuration of GTM.
  • Know how to publish and validate your tags on different sites.

The quality workflow will no longer hold any secrets for you.

What is the environments feature of Google Tag Manager?

Google Tag Manager offers a feature called Environments or simply GTM environments.

This feature let you create multiple environment and test new marketing technology integration in your test or staging server before going live.

It is critical to be able to test that different scripts or any other events or goals work properly before publishing them to Live.

To access the environment in Google Tag Manager, go to the Admin view and click on Environments.

Environments with Google Tag Manager

As you can see you have already two environments, Live and Latest:

  • Live is the one used by default for your production website
  • Latest represents the Latest version of your container. For instance, when you save a draft version, the version is available in the Latest environment.

Set up Test Environment with Google Tag Manager

It is up to you to pick the right naming or the one compliant with your company policy. In the following example, I will name my environment Staging.

To create a new environment, follow these steps:

  • Click on New from the environment panel
  • Set a Name and a URL
  • Click on Create Environment
  • Then a window popup will invite you to publish.
  • By doing this the new environment created will be exactly on the same level that the Live one (the one representing your Production website)
GTM - Publish to Staging

Congratulation, you have now three environments: Live, Latest, and Staging.

Now the last step is to install the snippet of the Staging Google Tag Manager environment on your staging website. The process is similar to what we’ve done previously:

  • From the environment panel, click on the Actions link
  • Copy the snippet of Staging and paste it to your staging website
Copy the snippet of Staging and paste it to  your staging website

Important note: as soon you create a new environment, you have to change as well the snippet install on your production. Get the snippet from the Live environment and replace it on your production site.

Great, now you have two different environments in Google Tag Manager.

So far, they have precisely the same configuration. Let’s test to add a change in Staging before releasing it to Production.

Quality assurance workflow with Google Tag Manager

Google Tag Manager let you set up a quality assurance process. It leverages the versioning and environment features.

Basically, the process is as follows:

  • Create a new version of your workspace that contains the tags to be tested
  • Publish the version on the pre-production environment and do some tests
  • If everything works, release the version on the production environment

To better understand the steps, we will install a dummy Javascript tag on the Staging environment, and we will test it. Then, we will deploy this tag on the production website.

Create a dummy tag first

The tag is a simple HTML/Javascript printing a “Hello” in the Javascript Console of your browser.

Create a new tag of type Custom HTML and copy the following code inside the HTML block:

<script>
console.log("Hello");
</script>
Javascript Tag with GTM

Then a new version of the workspace

Once the tag is created, from the “Workspace” panel click on “Submit”, and this time do not publish the tag. We will only want to create a new version of the workspace.

Create a new version of the workspace in Google Tag Manager.

We have two versions of the container or two different configurations available for the Tag Manager:

  • The first version containing the initial Google Analytics tag
  • And a second version with the Google Analytics tag and the “Hello” Tag

As you can see, only the version 1 is live and is at the moment applied to both Live and Staging environment.

Versioning with Google Tag Manager

Side note: As mentioned previously, Latest represents the last version of the container, which is now pointing to the version 2.

Now, our goal is to test the “Hello” tag on staging first.

Publish your changes to Staging

Go on the Version panel, and follow these steps:

  • Click on the version you want to publish to the staging (in our case the version 2)
  • Chose Publish To
  • Select the Staging environment
  • Click Publish
Publish To with GTM

If you refresh the Version panel, you can see now that the version 2 is applied to Latest and Staging.

Let’s verify that the script is working and saying “Hello” to the staging site.

Go the staging website, reload the page and open the developer console. You will see a friendly “Hello” message.

Hello message from Developer Console

Try the same test on your production site. You will not see a similar message. Indeed the production is still on the version 1 of the container.

The new tag is properly tested and works well. We will now publish to the “Live” or Production website.

Finally deploy your marketing tag to Production

Similar steps than previously:

  • Go back to the Versions panel
  • Click on the version 2
  • Publish to and then select the Live environment.

The version 2 of the container is now available to all environments. Feel free to test on the production website.

Keep in mind, that you can as well move back to a previous version at any time.

Control the marketing tag deployments

Using the Environments and Version features of Google Tag Manager together deliver a powerful mechanism.

And as we’ve just seen, it’s not as complicated as we think.

The mechanism let you test new integrations before deploying them to production. And this is very important for any enterprises using several environments. You don’t want to mess-up the Prod!

Go further with Google Tag Manager

This article is part of on advanced tutorial of Google Tag Manager and Analytics.

In the following articles, we will look at the advanced concepts that are often necessary for the configuration of professional websites.

I invite you to continue configuring your site by taking advantage of the Google Tag Manager environments by configuring Google Analytics across multiple domains.

Join the conversation