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

 <?php

switch ($_SERVER[‘HTTP_HOST’]) {

case ‘localhost’:

case ‘dev.clientdomain.com’:

case ‘staging.clientdomain.com’:

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

break;

case ‘www.clientdomain.com’:

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

break;

default:

$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>

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({‘gtm.start’:

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

j=d.createElement(s),dl=l!=’dataLayer’?’&l=’+l:”;j.async=true;j.src=

‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);

})(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).

dev_<TagType>_<TagName>_<TagID>

e.g. dev_GA_classic_pageview_UA-00000-2

live_<TagType>_<TagName>_<TagID>

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)

image065

Related post on this discussion is here.

0117 3361103

FREE GOOGLE TAG MANAGER BOOK

For the PDF Copy, please enter email address
DOWNLOAD
close-link
Click Me