The environments feature in Google Tag Manager is ideal for organizations that want to preview their container changes in a test environment before those changes are published. This feature is useful for organizations that use multi-tiered environments in their development workflow (e.g. 'development', 'staging', and 'production'.)
Setup overview
There are three high-level steps to set up environments with Tag Manager:
- Define your environments.
- Install the relevant container snippet for each environment on their respective sites.
- Publish the container to the desired environment.
You can set up as many environments as is required for your workflow, and you can publish any version of your container to any environment you have defined.
Tip: An alternative way to use environments is to use an environment's preview function. Share the preview link for whatever version of the environment you'd like to preview. With this method, you don't have to install and deploy a special environment code snippet.
Define environments
The first step is to define your environments. Decide what each environment will be called, and what the purpose of each environment will be. Often this is has already been established by your development team or organization. Here is a commonly-used convention:
- Dev – This server is what you and your team use for day-to-day website development.
- QA – A server that is used for quality assurance testing. Policy might be set such that all changes must pass through this server and be tested before those changes are moved to the live environment.
- Live – The server hosting the live version of your website; the version that is visible to your users.
Once you have your environments defined, you can configure them in Tag Manager:
- Click Admin.
- In the Container menu, click Environments.
- Click New. The Create Environment box appears.
- Enter a Name for your environment.
- Optional: Enter a Description and Destination URL.
- Optional: Check Enable Debugging by Default if you need the environment to always use preview mode.
- Click Create.
- You will be prompted to publish your environment. Click Publish Now to publish the environment. You will have the option to change the version of the container published to the environment with the Version menu. Your new environment should now appear in the Custom Environments list.
Install container snippets
The next step is to install your container snippets. This process is similar to installing a standard Tag Manager container snippet, except that you have to do this on every server that has a corresponding environment defined in Tag Manager. This step may require assistance from a developer or systems administrator to complete.
- In the Custom Environments listing, find the entry for the environment you would like to install.
- Click the Actions menu for that entry.
- Select Get Snippet.
- Copy the resulting code snippet and install it so that it will appear in the code of the target environment.
- Save and publish the website's code changes.
When you have custom environments defined, the Publish dialog will add a menu so that you can define to which server the changes will be published.
- Click Publish in the upper right corner of Tag Manager.
- Choose a selection from the Environment menu for where you want to publish your changes.
- Click Publish.
The Environments feature is designed for use with non-production environments. To ensure the best performance, you should install the standard Tag Manager container snippet on live/production websites.
Set versions
Once your custom environment has been defined, you can set that environment to any version of your container:
- In the Custom Environments list, find the entry for the environment you would like to install.
- Click the Actions menu.
- Select Publish To....
- Use the Version menu to select the desired container version for this environment.
- Click Publish Now.
Share previews
You can share previews of any environment with other people so that they may test it:
- In the Environments list, find the entry for the environment you would like to share a preview of.
- Click the Actions menu.
- Select Share Link.
- Copy the preview link and send it to a colleague.
Edit environments
To edit an environment:
- In the Custom Environments list, find the entry for the environment you would like to edit.
- Click the Actions menu.
- Select Edit Settings.
- Make changes to Name, Description, and Default URL as desired. Toggle the Enable Debugging by Default checkbox as desired.
- Click Save.
Revoke authorization code
If you have preview links sent out and you'd like to invalidate that preview, you can do so from the Actions menu:
- In the Custom Environments list, find the entry for the environment you would like to install.
- Click the Actions menu.
- Select Reset Link.
- A confirmation box will appear. Click Reset and Relink to cancel the old code and create a new one.
Note: This also will invalidate any container snippets that may be installed. This means that once an environment has had its authorization code revoked, an updated container snippet will need to be installed on the environment's server.
Versions
When you have environments defined, the Versions list will now show an Environments column, that indicates to which environment the version was published.