Setup Google Tag Manager Environments using GTM4WP
Google Tag Manager Environments is an advanced feature that allows you to publish different container version into different versions of your website. Environments are useful for organizations that use multi-tiered environments in their development workflow.
You may use a separate “development” version where programmers can easily improve site feature without risking the operation of your live site. It is usually also a good idea to have a “testing” or “sandbox” version where plugin updates can be tested before you upgrade them on your live site. This can prevent you from breaking the site when some new plugin version conflicts with another plugin or the theme itself. This can also allow you to test new improvements and changes in your Google Tag Manager container without the need to publish changes directly on your live site.
Please note: if you use environments in GTM4WP, only enter one GTM container ID in plugin options as currently only one container is supported if using environments.
This page shows you the steps you need to go through in order to setup your GTM environment in GTM4WP.
1. Create your Google Tag Manager environments
First of all, read this GTM help center article to learn how to create your separate environments within GTM.
2. Get the environment parameters
Visit Admin, then Environments under your container and click on the Actions button at the end of the environment, that you are currently setting up.
Select the Get Snippet option from the menu.
3. Find the gtm_auth parameter
Look at the first container code and locate the gtm_auth
parameter in it. Copy the value of this parameter to your clipboard (note: the value might continue to show on a new line!)
Open GTM4WP options and navigate to the Advanced tab. Enter the value into the appropriate field.
4. Find the gtm_preview parameter
Look at the container code again and locate the gtm_preview
parameter in it. Copy the value of this parameter to your clipboard.
Open GTM4WP options and navigate to the Advanced tab. Enter the value into the appropriate field.
Hard coding for better site migration opportunities
You can also hard code both the container ID and the environment parameters into your wp-config.php file using PHP constants.