「ADAM 筆記」How to Run Multiple GTM Containers on a Page

    摘自: https://www.clickinsight.ca/blog/run-multiple-gtm-containers

<

iframe src=\”https://www.clickinsight.ca/blog/run-multiple-gtm-containers\” class=\”iframe-full-content\”>

How to Run Multiple GTM Containers on a Page

How to Run Multiple GTM Containers on a Page

Do you have multiple Google Tag Manager containers running on your website?How to run multiple GTM containers

If so, you should ensure that your implementation follows Google’s recently-updated guidance:

Multiple containers are now officially supported. Multiple data layers are NOT supported.

In general, we recommend using a single container whenever possible. If external agencies or vendors need tags added to your site, it is better to have them send you the required code and to deploy it through your own GTM container, rather than adding a GTM container for each agency.

There are valid use cases for multiple containers, especially if you need the ability to restrict editing or publishing permissions to certain sets of tags. Since user permissions are assigned at the container level, this can currently only be accomplished by splitting your implementation into multiple containers.

Consider the scenario in which a company’s global office manages the websites of all its regional subsidiaries. Each regional office needs the ability to add tracking pixels for its local marketing campaigns, but regional users should not be able to affect the analytics tracking configured by the global office.

With a single container, either every tagging request of the regional office would need to go through global HQ or each regional office would need to have Edit and Publish permissions on the entire container. If both these options are unworkable, multiple containers would allow the global office to maintain its own tracking, while each regional office could implement tagging by themselves as needed.

Until recently, there was no official support for multiple GTM containers on a page. Unofficially, the common guidance previously was to rename the dataLayer for each container. However, Google’s new documentation explicitly states that using multiple data layers is not supported and can cause issues with your tracking:

Note that you can use only a single common data layer for all Google Tag Manager containers on a page because using more than one data layer can cause some triggers to stop working and could have other implications. So don’t rename the data layer for a subset of containers on the page.

Hence, if you have multiple data layers on your site, your tagging implementation may behave unpredictably or certain parts may break. We recommend updating your code in accordance with Google’s documentation for multiple containers.

What should I do if I have multiple data layers?

  1. Update any legacy GTM V1 “Listener” tags to V2 Triggers.
    • Listener tags were preserved when V1 containers were migrated to V2, hence any listener tags must be manually converted into triggers.
    • Running multiple GTM containers with v1 listener tags may cause issues.
  2. Use a single data layer name for all your containers.
    • We recommend using the default dataLayer whenever possible.
    • If necessary, choose a custom name (e.g. myCompanyDataLayer) and use it for all your containers.
    • Ensure that any dataLayer.push() functions reference the name of your common data layer, i.e. dataLayer.push() or myCompanyDataLayer.push()

Have you had any challenges with using multiple GTM containers? Let us know!

By |


2018-03-05T13:19:02+00:00

December 8th, 2015|1 Comment

One Comment

  1. Kartikeya
    May 8, 2018 at 9:16 am – Reply
    Thanks so much for this! Very insightful:)

Leave A Comment Cancel reply



            <script type=\"text/javascript\">
            jQuery( document ).ready( function() {
                var ajaxurl = \'https://www.clickinsight.ca/wp-admin/admin-ajax.php\';
                if ( 0 < jQuery( \'.fusion-login-nonce\' ).length ) {
                    jQuery.get( ajaxurl, { \'action\': \'fusion_login_nonce\' }, function( response ) {
                        jQuery( \'.fusion-login-nonce\' ).html( response );
                    });
                }
            });
            </script><script type=\"text/javascript\" src=\"https://www.clickinsight.ca/wp-content/plugins/better-archives-widget/baw-script.min.js?ver=2.2.1\"></script><script type=\"text/javascript\">

/* */

/* */

/* */

/* */

/* <![CDATA[ */
var avadaPortfolioVars = {\"lightbox_behavior\":\"all\",\"infinite_finished_msg\":\"All items displayed.\”,\”infinite_blog_text\”:\”Loading the next set of posts…\”,\”content_break_point\”:\”800\”};
/* ]]> */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* <![CDATA[ */
var fusionBlogVars = {\"infinite_blog_text\":\"Loading the next set of posts…\”,\”infinite_finished_msg\”:\”All items displayed.\”,\”slideshow_autoplay\”:\”1\”,\”slideshow_speed\”:\”7000\”,\”pagination_video_slide\”:\”\”,\”status_yt\”:\”1\”,\”lightbox_behavior\”:\”all\”,\”blog_pagination_type\”:\”Pagination\”,\”flex_smoothHeight\”:\”false\”};
/* ]]> */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

/* */

var rouletteVariant = function(){
var numberOfVariants = 10;
var cookieName = \’rr\’;
var randomNumber = Math.floor(Math.random() * numberOfVariants) + 1
var cookieLife = 30*60*1000; //30 minutes

function setCookie(data, name, timeToKeep, topLevel) {
var expiry = new Date(new Date().getTime() + timeToKeep),
hostname = document.location.hostname;

if (topLevel === true) {
hostname = hostname.split(\”.\”).slice(-1 * 2).join(\”.\”);
}
document.cookie = name + \’=\’ + data + \’;domain=\’ + hostname + \’; path=/; expires=\’ + expiry.toGMTString() + \’;\’;
}
setCookie(randomNumber, cookieName, cookieLife, true);
location.reload(true);
window.scrollTo(0, 0);
}

var rouletteButton = document.querySelector(\”a#rouletteButton\”);

if(!!rouletteButton) {
rouletteButton.addEventListener(\’click\’, function(e){

});
}

document.addEventListener(\’click\’, function (e) {
if(e.target.className.indexOf(\”wp-image-15230\”) > -1) {
if(!!e.target.parentElement) {
if(!!e.target.parentElement.getAttribute(\”id\”) && e.target.parentElement.getAttribute(\”id\”) == \”rouletteButton\”) {
//console.log(\”button clicked! – parent method\”);
e.preventDefault();
rouletteVariant();
}
}
} else if (!!e.target.getAttribute(\”id\”) && e.target.getAttribute(\”id\”) == \”rouletteButton\”) {
//console.log(\”button clicked! – direct method\”);
e.preventDefault();
rouletteVariant();
}
});

jQuery(document).ready(function() {
jQuery(\’.baw-year\’).append( \” \” );
jQuery(\’.click-here\’).live( \”click\”, function() {
jQuery(this).siblings(\’ul\’).toggleClass(\’show-months\’)
});
jQuery(\’#baw_widgetarchives_widget_my_archives-2 > ul, .sidebar #categories-3.widget_categories ul\’).hide();
jQuery(\’#baw_widgetarchives_widget_my_archives-2 > .heading\’).click(function(){
jQuery(this).toggleClass(\’arrow-up\’);
jQuery(\’#baw_widgetarchives_widget_my_archives-2 > ul\’).slideToggle();
});
jQuery(\’.sidebar #categories-3.widget_categories .heading\’).click(function(){
jQuery(this).toggleClass(\’arrow-up\’);
jQuery(\’.sidebar #categories-3.widget_categories ul\’).slideToggle();
});
});

function adjustSidebar() {
function getOuterHeight(elem) {
var elmHeight, elmMargin;
if(document.all) {// IE
elmHeight = elem.currentStyle.height;
elmMargin = parseInt(elem.currentStyle.marginTop, 10) + parseInt(elem.currentStyle.marginBottom, 10);
} else {// Mozilla
elmHeight = document.defaultView.getComputedStyle(elem, \’\’).getPropertyValue(\’height\’).replace(\”px\”, \”\”);
elmMargin = parseInt(document.defaultView.getComputedStyle(elem, \’\’).getPropertyValue(\’margin-top\’)) + parseInt(document.defaultView.getComputedStyle(elem, \’\’).getPropertyValue(\’margin-bottom\’));
}
return (+elmHeight + +elmMargin) + \”px\”;
}

var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var sidebar = document.querySelector(\”#sidebar\”);

console.log(\”width: \” + width);
console.log(sidebar);

if(width > 800) {
var topslider = document.querySelector(\”.fusion-flexslider\”);

if(!!topslider) {
var sliderOuterHeight = getOuterHeight(topslider);
}

if(!!sidebar) {
sidebar.setAttribute(\”style\”, \”float: right; margin-top: \” + sliderOuterHeight + \” !important;\”);
}
} else {
if(!!sidebar) {
sidebar.setAttribute(\”style\”, \”float: right; margin-top: 0px !important;\”);
}
}
}

adjustSidebar();

window.addEventListener(\”resize\”, function(){
console.log(\”resize\”);
adjustSidebar();
});

window.optimizeCoursePages = function(){
var pagepath = window.location.pathname;
var content = document.querySelector(\”.post-content\”);
console.log(\”pagepath: \” + pagepath);
console.log(\”content elem:\”);
console.log(content);
if(!!pagepath && !!content) {
if(pagepath.indexOf(\”/training/google-analytics-google-tag-manager-courses-toronto\”) == 0) {
console.log(\”courses landing\”);
content.innerHTML = \’

Make Better Decisions. Improve Your Results.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *