Google Tag Manager | What are the best practices for managing multiple environments?
Introduction & Purpose
Organizations who use multiple environments in their development process (ex. development, staging, and production), should reference this guide to install one GTM container across each of those environments.
Difficulty:
A developer may be required
Steps
Google Tag Manager
- Navigate to Admin > Environments (under the Container column)
- Click New then enter the name of your Environment
- Check Enable Debugging by Default which enables preview mode — important for debugging and QA
- Click Create and Publish Now.
Server
- Under Admin > Environments, for each environment, click Actions, Get Snippet to see the required code snippet
- Copy and paste the code snippet into your target environment(s)
- Save and publish changes to website code
Now with custom environments defined, GTM will allow you to specify an environment to target on Publish.
Validation
After publishing your updates to server code, load the site from that environment and right click > inspect to view the HTML. Find your GTM code snippet and ensure that it matches the snippet provided by GTM, especially the 'gtm_auth' and 'gtm_preview' values.