• Resolved ac987

    (@amircisija)


    Greetings, I have some problems implementing google consent mode. But while trying to add this consent mode, I notices some problem.

    Google tag manager seems to be loaded on page load, and when users accept cookies, it loads again. Since I added the GTM code in the Additional Cookies Head Section, it should only load when user accepts. Default status of that category is disabled.

    As we have wpml multidomain setup this is the code that I use to switch gtm loading depending on domain:

    var currentDomain = window.location.hostname;
    
    var domainContainerMap = {
    
    ? ? 'www.domain.com': 'GTM-xxxxxxx',
    
    ? ? 'www.domain.de': 'GTM-xxxxxxx',
    
    };
    
    if (currentDomain in domainContainerMap) {
    
    ? ? var containerId = domainContainerMap[currentDomain];
    
    ? ? var noscriptIframe = document.createElement('noscript');
    
    ? ? var iframe = document.createElement('iframe');
    
    ? ? iframe.src = 'https://www.googletagmanager.com/ns.html?id=' + containerId;
    
    ? ? iframe.height = '0';
    
    ? ? iframe.width = '0';
    
    ? ? iframe.style.display = 'none';
    
    ? ? iframe.style.visibility = 'hidden';
    
    ? ? noscriptIframe.appendChild(iframe);
    
    ? ? document.body.appendChild(noscriptIframe);
    
    ? ? var script = document.createElement('script');
    
    ? ? script.innerHTML = "(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='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','" + containerId + "');";
    
    ? ? document.head.appendChild(script);
    
    }

    I followed the implementation guide for google consent mode, but nothing seems to be working.
    Any advice would be helpfull.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Moove Agency

    (@mooveagency)

    Hello,

    Thanks for using our plugins.

    This really depends on what options you activated in the plugin settings.

    The GTM loads on page load because with GTM you only update consent settings depending on user preferences. But wether this works as intended really depends on your setup and the settings you activated.

    Is the script you listed hard-coded anywhere in your site?

    Also, if you use our ‘Integrations’ tab, you should not be inserting GTM code anywhere else in the plugin.

    Furthermore, you seem to be using some advanced multi-linguage method that complicates things further.

    Unfortunately we can’t advise on one-to-one basis as the Google Consent Mode v2 is an advanced integration method. Your development team should check the integrations and inspect your GTM scripts using Google Tag Assistant to see which tags are fired and how your tags operate.

    Alternatively, our plugin also offers the standard GTM integration method that we recommend for non-technical users because the standard method only requires you to add your GTM ID inside of the ‘Integrations’ tab within our plugin.

    Hope this helps.

    Thread Starter ac987

    (@amircisija)

    Hello,

    we have 2 GTM codes for 2 domains, therefore we can’t use that integration methods. Would the premium version allow different GTM tags for 2 domains?

    Ideally the script above should fire when user accepts the cookies since I added it in the Additional Cookies Head section, it should load the google tag manager according to the domain, but like I said, it loads it on page load, and after accepting cookies, it loads it again which is not good.

    The code is not hardcoded anywhere in the theme. I tried the cookie consent mode integration with hardcoding some parts of the code to the header.php file, and the cookie update in the Addition Cookies section, but nothing works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Content mode, gtm, mulltidomain’ is closed to new replies.