A Quick Guide to Environments in GTM

As a website owner or marketing manager of an e-commerce portal or business website, you will likely have to rely on the convenience of Google Analytics (GA) and Google Tag Manager (GTM). While GA provides you with better reports, GTM allows GA to do so by making it easy to manage all your tags in one place, for better tracking and analytics of your website or blog traffic.

With its easy-to-use interface and readily available debug mode, GTM empowers you to easily add tags to websites. However, there’s a good chance enterprises like yours are using multi-user environments. This is where GTM’s “Environments” feature comes in handy by providing you with better control over tag deployment. But how does GTM support optimal deployment of tags?

For regular tracking of your website, you deploy tags related to advertising pixels, analytics tracking code and so on. However, there’s always a possibility that you may have to work with different container versions, and you may not want to take the risk of directly deploying any untested complex tags to your live website. With the Environments feature, you can now publish your tags after thoroughly testing them on your live website (in an environment that closely resembles your production site). The Environments functionality equips you with the ability to publish GTM container versions to specific environments, thereby providing you with better control over tag deployment.

There was a long wait for this Environments feature, which finally ended in late 2015. But how important is this feature in GTM, and how can you set it up? We will explore its overall impact in this article, as well as give step-by-step set-up instructions.

Overview of GTM Environments and its Importance

With the release of this feature, it’s now possible for you to define multiple server environments in GTM. These environments reflect browser cookies that are used to link a GTM container version (state) with the user’s browser when the user tries to view that particular container state. In simple terms, if you follow the ideal process for better QA (quality assurance) — testing on a staging server before going to a production server —  then you can easily create an environment in GTM, and then publish container versions in that specific environment.

Also, if your company is one that uses multi-tiered environments (e.g., for development, staging, production) as part of its development workflow, the Environments functionality is a real boon.

Before Environments came into effect, you had to fetch a new authentication token every time a container version changed. This linking of the token to a particular container version used to make the QA process quite cumbersome. In an ideal scenario, you would want the browser cookies to be associated with the environment, not the version.

With the Environment functionality, you can still “Share a Preview,” to share your container’s configuration link for further testing by others.. Your Google Tag Manager is now able to distribute environment tokens without authentication being revoked, and the specific token continues to have access to all versions that are published in that specific environment.

This makes GTM and tag deployment much more manageable—either by sharing a link (as you may have been doing before the release of the Environments feature), or by inserting a script (piece of code) into the page templates of each environment.

Setting Up Multiple Environments in GTM

The beauty of this new feature is that it empowers you to add as many environments to your workflow as you need and publish any container version (state) to any of those environments. After publishing, you can share preview links within your team for testing.

Here is the process for setting up different environments for your Google Tag Manager account:

Define Your Environments

Your team needs to follow a naming convention scheme for each of your servers before you move to real-time testing in different environments. Each of your containers should be set up with a LIVE environment by default to point toward the currently published container version, and you don’t need to define an additional environment for these.

However, you may have to define the other environments for development (for example,  Dev) and quality assurance testing (for example, QA). The usual development work happens in the Dev environment, while all your updates need to be tested thoroughly in the QA environment before they can be passed on to the production (LIVE) server.

Set Up Your Custom Environments

After finalizing your naming conventions, you can proceed to setting up custom GTM environments, as follows:

  • Choose the “Admin” option.
  • Select “Environments” alternative from the Container menu.a-quick-guide-1
  • Select “New,” and the “Create New Environment” box would appear.
  • Enter a name for your environment, which is a mandatory step. The default URL and description fields are optional.a-quick-guide-2
  • It’s up to you whether to select the option, “Enable Debugging by Default.”
  • Finally, click on “Create,” and your newly created environment will be displayed in the list of “Custom Environments.”

Installing Container Snippets For Every Environment

You can ask your developer team to install relevant container snippets for every server against which a particular environment is defined in your GTM. Your team can follow the steps below to execute this task to perfection:

  • Under your “Custom Environments” listing, identify the environment that you need to install.
  • Select the “Actions” menu.a-quick-guide-3
  • Once you choose “Get Snippet,” you will get a corresponding code snippet that you need to copy and later install.
  • Save the updates and publish these code changes to your website(s).

After you have defined your custom environments, you will get a menu from “Publish Dialog” to define the server where the updates have to be published. All you have to do is:

  • From the upper right corner of your Google Tag Manager account, select “Publish.”
  • Select your preferred option from the “Environment” menu where you intend to publish the updates.
  • Finally, click “Publish.”

As you can see, it’s fairly simple to publish the container to your desired environment.

Other Functions Possible with GTM Environments

Setting Environment to Container Versions

  • Go to the “Actions” menu from your “Custom Environments” listing for the environment of your choice.
  • Select the “Publish To”’ option.
  • The version menu will give you the requisite container state (version) for the relevant environment.

Sharing a Preview

  • You can share your environment’s container configuration link with anyone you know so they can test it. To do this, complete the below steps:
  • Under your “Environments” listing, choose the environment’s container for which you want to share a preview.

Select the “Actions” menu and choose “Share Preview.” This will give you a URL to copy and share with whomever you want to test your changes.a-quick-guide-4Invalidating a Preview

If, after you send preview links, you realize that they are not the correct ones or that the people you shared them with should no longer have access to them, you can invalidate the links by revoking the authorization code. Follow these steps:

  • Under your “Custom Environments” listing, choose the environment you wish to make authorization changes to.
  • From the “Actions” menu, select “Reset Link,” which will bring up a confirmation box.
  • Choose “Reset and Relink” to invalidate the old code and select the new code.

The additional, streamlined functionality that Environments provides helps GTM to function better across servers and teams. It also optimizes the “Share Preview” feature and tag deployment process. Following the above steps can help you take advantage of this new GTM feature.

We hope this information proves useful to you. Feel free to share your questions in the comments below.

If you like my articles,