Retrieval of Conversion Code on Page Load

367 views
Skip to first unread message

Krishna Kishore

unread,
Jul 9, 2018, 5:27:37 AM7/9/18
to AdWords API and Google Ads API Forum
I'm trying to retrieve the Google Event Snippet, the conversion for a customer from Adwords API, but the format is different from what is being shown in the Adwords UI, for example in the Adwords UI for a particular customer the Page Load  Conversion code looks
like<!-- Google Code for XXXXXXXXX Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_conversion_label = "P_1234_1234567890123";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/
javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="/
/www.googleadservices.com/pagead/conversion/123456789/?label=P_1234_1234567890123&amp;guid=ON&amp;script=0"/>
</div>
</noscript>


But the response that I get from ConversionTrackerField from API looks like

<script>
  gtag
('event', 'conversion', {'send_to': 'AW-123456789/P_1234_1234567890123'});
</script>


I need the response of type that is being shown in the Adwords API, Is there any way to do that??

Milind Sankeshware (AdWords API Team)

unread,
Jul 9, 2018, 3:42:16 PM7/9/18
to AdWords API and Google Ads API Forum
Hi Krishna,

In AdWords API, you can use ConversionTrackerService.get() to get googleeventsnippet field. Please refer the Java sample code here. The sample in other languages can be found here. I hope this will help you. If not, please elaborate your question so that I can assist you in a better way.

Thanks,
Milind, AdWords API Team.

Krishna Kishore

unread,
Jul 10, 2018, 3:06:16 AM7/10/18
to AdWords API and Google Ads API Forum

Hey Milind, As explained in the Question, I'm already using the ConversionTrackerService and fetching the google Event snippet.  The event snipped that I get from ConversionTrackerService is 
<script>
  gtag
('event', 'conversion', {'send_to': 'AW-123456789/P_1234_1234567890123'});
</script>
The response which I get from the API is different from the Conversion Snippet that is being shown in the conversions page of Adwords, which looks like
like<!-- Google Code for XXXXXXXXX Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_conversion_label = "P_1234_1234567890123";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/
javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="/
/www.googleadservices.com/pagead/conversion/123456789/?label=P_1234_1234567890123&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

So what my question is that, Is there any way to get the conversion code which is similar to what is being shown in the Adwords conversion page through Adwords API or Is there any way to get the <noscript> code from the above snippet through Adwords API?

Milind Sankeshware (AdWords API Team)

unread,
Jul 10, 2018, 4:05:29 PM7/10/18
to AdWords API and Google Ads API Forum
Hi Krishna,

From the UI, Global site tag and Event snippet is matching with the API googleEventSnippet and googleGlobalSiteTag values. Please find the attached the UI screen shot. I ran the ConversionTrackerService.get in my test account and get the values below:

1. googleEventSnippet:
<googleEventSnippet>&lt;!-- Event snippet for Earth to Mars Cruises Conversion # 1517504244156 conversion page --&gt;
&lt;script&gt;
  gtag('event', 'conversion', {
      'send_to': 'AW-827166599/ebXQCM6E8XsQh5-2igM',
      'aw_remarketing_only': true
  });
&lt;/script&gt;
</googleEventSnippet>

2. googleGlobalSiteTag:
<!-- Global site tag (gtag.js) - Google AdWords: 827166599 -->
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-827166599');
</script>

If you are referring any other screenshot please share with me so that I can troubleshoot the issue. You could use 'Reply privately to author' option while responding. 
Site and event tag.png

Milind Sankeshware (AdWords API Team)

unread,
Jul 11, 2018, 1:51:29 PM7/11/18
to AdWords API and Google Ads API Forum
Hi Krishna,

If you are using the v201710 version of the API, you will be able to get the code using snippet field via ConversionTrackerService.get(). This will match the code given in the In AdWords old interface (as you attached in your previous email). From V201802 version of the API, several changes were made to support global site tags and event snippets, which offer more streamlined tagging across all Google products. If you are using the snippet field to track conversions, please migrate to the new global site tags and event snippets instead. For more information please refer to the release notes. Let me know if you have any further questions.
Reply all
Reply to author
Forward
0 new messages