When setting up a DEV and LIVE environment there are 3 solutions, depending on the complexity of your installation, flexibility of your server and your attitude towards risk.

Note: At the time of writing, GTM does not support an external API for source control, thus configurations need to be manually copied. However, tags can be copied and iMacro browser automation can be used instead.

1) Two separate containers (GTM-dev and GTM-dev) insert via php server-side switch (safest option):


switch ($_SERVER[‘HTTP_HOST’]) {

case ‘localhost’:

case ‘dev.clientdomain.com’:

case ‘staging.clientdomain.com’:

$gtm_account_id = ‘GTM-DEV’; // Dev GTM


case ‘www.clientdomain.com’:

$gtm_account_id = ‘GTM-LIVE’; // LIVE GTM



$gtm_account_id = ‘GTM-LIVE’; // default to LIVE



<!– Google Tag Manager –>

<noscript><iframe src=”//www.googletagmanager.com/ns.html?id=GTM-<?php echo $gtm_account_id ?>

height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>


new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],



})(window,document,’script’,’dataLayer’,’GTM-<?php echo $gtm_account_id ?>‘);</script>

<!– End Google Tag Manager –>


2) One container with prepended identifier of “dev | live” (less dangerous option, but double number of tags).


e.g. dev_GA_classic_pageview_UA-00000-2


e.g. live_GA_classic_pageview_UA-00000-1


3) One container using preview & debug extensively! (most dangerous option, as it requires write access to live)


Related post on this discussion is here.

0117 3361103