Content mode, gtm, mulltidomain |

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 = {

    '': 'GTM-xxxxxxx',

    '': 'GTM-xxxxxxx',


if (currentDomain in domainContainerMap) {

    var containerId = domainContainerMap[currentDomain];

    var noscriptIframe = document.createElement('noscript');

    var iframe = document.createElement('iframe');

    iframe.src="" + containerId;


    iframe.width="0"; = 'none'; = 'hidden';



    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=""+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','" + containerId + "');";



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


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer