Download and test GTM4WP 2.0.0 beta2. Don’t wait for others to test it, they are waiting for you!

Skip to content
Facebook Twitter Github RSS
Google Tag Manager for WordPress
  • Home
  • FeaturesExpand
    • Basic features of GTM4WP

      You can use many post or page attribute in you Google Tag Manager setup even for custom post types and taxonomies.

      Basic data

      Page / post attributes

      Site search

      User data

      Multisite data

      3rd party data

      Browser attributes

      Device attributes

      Operating system attributes

      Weather conditions

  • SetupExpand
    • Setup advanced GTM4WP features

      Integrate your measurement with WooCommerce, setup Google Analytics 4, Google Ads remarketing or conversion tracking maximizing capabilities.

      WooCommerce related

      Google Analytics 4

      Google Ads – Dynamic Remarketing

      Google Ads – Conversion tracking

      Google Ads – Enhanced Conversions

      Other setup articles

      Cache Safe Data Layer

      Exclude WordPress admins

      Embedded media players

  • DevelopersExpand
    • Information for developers and WP managers

      There are several tools in GTM4WP to support your special needs and to adjust plugin behavior to your website or WooCommerce shop.

      Do you want to contribute with a bugfix or a new feature? Visit the GTM4WP’s GitHub page!

      For Developers

      Actions and filters

      WP themes + Proper ecommerce tracking

      For WP managers

      Setup GTM Environments

      Hard code GTM parameters

  • Blog
  • GDPR
Download
Google Tag Manager for WordPress
Home / GTM4WP For Developers / Setup Google Tag Manager Environments using GTM4WP

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.

Every container row in the plugin settings carries its own environment parameters, so a site that loads several containers can put each of them into a different environment. Both the gtm_auth and the gtm_preview value of a row have to be filled in before that container switches to an environment. Leave both empty to load the live version of it.

This page describes GTM4WP 2.0.0 and newer. Where the legacy 1.x versions of the plugin behaved differently, the older behavior is marked with a bold GTM4WP 1.x: lead-in.

GTM4WP 1.x: the two parameters were entered once on the Advanced tab and applied to the whole site, and only one container could be used with environments. With several container IDs configured, only the first one was loaded.

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
  • 2. Get the environment parameters
  • 3. Find the gtm_auth parameter
  • 4. Find the gtm_preview parameter
  • What the plugin checks when you save
  • Hard coding for better site migration opportunities

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.

Access the Get Snippet menu to retrieve your Google Tag Manager environment parameters.

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!)

Find the gtm_auth environment parameter in the container code.

Open the plugin settings, find the row of your container in the Google Tag Manager container section and paste the value into its Environment gtm_auth column.

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.

Find the gtm_preview environment parameter in the container code.

Paste the value into the Environment gtm_preview column of the same container row.

What the plugin checks when you save

Both values are validated when you save the settings. A gtm_preview value looks like env-4, and a gtm_auth value contains only letters, numbers, hyphens and underscores. A value in any other format is refused with a message that names the container row it belongs to, so a typo cannot end up in the loader URL of your container.

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.

© 2026 Google Tag Manager for WordPress - Privacy policy

  • WordPress.org plugin page
  • Plugin support
  • Plugin reviews
  • Home
  • Features
    • Basic features of GTM4WP

      You can use many post or page attribute in you Google Tag Manager setup even for custom post types and taxonomies.

      Basic data

      Page / post attributes

      Site search

      User data

      Multisite data

      3rd party data

      Browser attributes

      Device attributes

      Operating system attributes

      Weather conditions

  • Setup
    • Setup advanced GTM4WP features

      Integrate your measurement with WooCommerce, setup Google Analytics 4, Google Ads remarketing or conversion tracking maximizing capabilities.

      WooCommerce related

      Google Analytics 4

      Google Ads – Dynamic Remarketing

      Google Ads – Conversion tracking

      Google Ads – Enhanced Conversions

      Other setup articles

      Cache Safe Data Layer

      Exclude WordPress admins

      Embedded media players

  • Developers
    • Information for developers and WP managers

      There are several tools in GTM4WP to support your special needs and to adjust plugin behavior to your website or WooCommerce shop.

      Do you want to contribute with a bugfix or a new feature? Visit the GTM4WP’s GitHub page!

      For Developers

      Actions and filters

      WP themes + Proper ecommerce tracking

      For WP managers

      Setup GTM Environments

      Hard code GTM parameters

  • Blog
  • GDPR
Search