Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

Google Conversion Tracking Tag

Avatar

Level 4

Hello, everyone,

I want to implement the new Google Conversion Tracking tag in Adobe Tag Manager.

Can anyone help me?

<!-- Global site tag (gtag.js) - Google Ads: 123456789 -->

<script async src="https://www.googletagmanager.com/gtag/js?id=AW-123456789"></script>

<script>

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

  function gtag(){dataLayer.push(arguments);}

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

  gtag('config', 'AW-123456789');

</script>

<!-- Event snippet for Example conversion page -->

<script>

  gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',

    'value': 1.0,

    'currency': 'USD'

  });

</script>

From this I would like to make the following:

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

1 var done = false;

2  

3 dcJS.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=' + document.__dtm_googleConversionIDGST[0] + ';');

4 dcJS.setAttribute('type','text/javascript');

5  

6 document.body.appendChild(dcJS);

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

8    if(!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {

9    done = true;

10    callback();

11  

12    // Handle memory leak in IE

13    dcJS.onload = dcJS.onreadystatechange = null;

14    document.body.removeChild(dcJS);

15    }

16 };

17 function callback(){

18    if(done){ 

19    /* <![CDATA[ */

20    window.google_trackConversion({

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

22    function gtag(){dataLayer.push(arguments);}

23    gtag('js', new Date());

24    gtag('config', '" + document.__dtm_googleConversionIDGST[0] + "');

25    });

26    //]]>

27    }

28 }

But you can't.

I get error messages.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I would do the following.

Go to the third-party section of the rule select async javascript option in DTM.  (set conversion tag fire condition in the rule itself)

1. Add the following code to set gtag.js

     Note: //Replace "AW-123456789" with your AdWords account id.

_satellite.loadScript("https://www.googletagmanager.com/gtag/js?id=AW-123456789"); //Replace "AW-123456789" with your adword account id.

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

                    function gtag() {

                        dataLayer.push(arguments)

                    };

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

                    gtag('config', 'AW-123456789');  //Replace "AW-123456789" with your adword account id.

                };

2. Now set following conversion code.

gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567', //Replace "AW-123456789" with your adword account id/value.

    'value': 1.0,

    'currency': 'USD'

  });

Note:

//Replace "AW-123456789" with your AdWords account id and "AbC-D_efG-h12_34-567" with conversion value id.

//Replace event "conversion" with custom conversion event eg. "view_item" etc.

Not sure what "document.__dtm_googleConversionIDGST[0]"  does in your code, but in case you want to pass additional data on the conversion, use conversion code section instead. Remove comments in code anything after // ... before publishing in DTM.

Good Luck!

Asheesh

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

I would do the following.

Go to the third-party section of the rule select async javascript option in DTM.  (set conversion tag fire condition in the rule itself)

1. Add the following code to set gtag.js

     Note: //Replace "AW-123456789" with your AdWords account id.

_satellite.loadScript("https://www.googletagmanager.com/gtag/js?id=AW-123456789"); //Replace "AW-123456789" with your adword account id.

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

                    function gtag() {

                        dataLayer.push(arguments)

                    };

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

                    gtag('config', 'AW-123456789');  //Replace "AW-123456789" with your adword account id.

                };

2. Now set following conversion code.

gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567', //Replace "AW-123456789" with your adword account id/value.

    'value': 1.0,

    'currency': 'USD'

  });

Note:

//Replace "AW-123456789" with your AdWords account id and "AbC-D_efG-h12_34-567" with conversion value id.

//Replace event "conversion" with custom conversion event eg. "view_item" etc.

Not sure what "document.__dtm_googleConversionIDGST[0]"  does in your code, but in case you want to pass additional data on the conversion, use conversion code section instead. Remove comments in code anything after // ... before publishing in DTM.

Good Luck!

Asheesh