Expand my Community achievements bar.

SOLVED

Google gtag in DTM

Avatar

Level 2

Hello Everyone!

Just wanted to know how do you guys deploy the Google gtag via DTM to collect the audiences for remarketing lists in DV360 or Google Ads?

As instructed by stewarts16448458​ on this thread, I deployed the gtag as a page top rule (Sequential HTML), however the Remarketing lists within the Google Ads  UI weren't populating. When I checked with the Google Ads Support team, they got back to me saying that the setup isn't right as they want the gtag to be injected directly on the page (i.e. not in an iframe and not run server-side).

So I tried converting the gtag to JS as shown below and it looks it is working. However I'd love to know if you know of any easier and efficient way of doing this.

var dcJS = document.createElement("SCRIPT");

var done = false;

dcJS.setAttribute("src", "//www.googletagmanager.com/gtag/js?id=AW-XXXXXXXX");

dcJS.setAttribute("type", "text/javascript");

document.body.appendChild(dcJS);

dcJS.onload = dcJS.onreadystatechange = function() {

  if (

    !done &&

    (!this.readyState ||

      this.readyState === "loaded" ||

      this.readyState === "complete")

  ) {

    done = true;

    callback();

    // Handle memory leak in IE

    dcJS.onload = dcJS.onreadystatechange = null;

    document.body.removeChild(dcJS);

  }

};

function callback() {

  if (done) {

    /* <![CDATA[ */

    window.dataLayer = window.dataLayer || [];

    function gtag() {

      dataLayer.push(arguments);

    }

    gtag("js", new Date());

    gtag("config", "AW-XXXXXXXXX");

  }

  //]]>

}

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Are you absolutely sure that you deployed it as Sequential HTML?

What you describe (loading in an iframe) would indicate that it had been deployed as Non-Sequential HTML. 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Are you absolutely sure that you deployed it as Sequential HTML?

What you describe (loading in an iframe) would indicate that it had been deployed as Non-Sequential HTML. 

Avatar

Community Advisor

Have you had a chance to check on this?  If my suggested solution did not work, I really would like to understand what went wrong.

-Stew