0

I have got following code from Google AdWords.

<script type="text/javascript">
    /* <![CDATA[ */
        var google_conversion_id = 973348620;
        var google_conversion_language = "en";
        var google_conversion_format = "3";
        var google_conversion_color = "ffffff";
        var google_conversion_label = "uffQCOz32QrMe70gM";
        var google_conversion_value = [BookingValue];;
        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/973348620/?value=[BookingValue];&amp;label=uffQCOz32QrMe70gM&amp;guid=ON&amp;script=0"/>
    </div>
</noscript>

I have designed my code using knockoutjs as single page application.

I need to add this tracking code on success event of ajax call. So I need to implement all above code inside javascript code.

xxbinxx
  • 1,527
  • 11
  • 18
Janith Widarshana
  • 3,213
  • 9
  • 51
  • 73

2 Answers2

2

I'd recommend using the proper asynchronous version of the Google tag instead of doing any craziness of adding the synchronous version of the tag via script tags to the DOM.

I answered this in another thread talking about angular.js which is very similar to knockout.js so the same answer should apply: How do I adapt a Google AdWords tracking pixel for use in an AngularJS app?

Hope that helps!

Community
  • 1
  • 1
matt1
  • 1,175
  • 7
  • 14
0
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "google code";

document.head.appendChild(s);

Or

document.body.appendChild(s);
artm
  • 8,554
  • 3
  • 26
  • 43
  • This code is adding html element to body or head.But this is updating google adword service.Is there any way to update google adword ? – Janith Widarshana Sep 02 '14 at 12:48
  • 1
    I thought you meant adding the script, you mean registering the conversion with google? I think you need to call _trackEvent(category, action, opt_label, opt_value, opt_noninteraction) or _gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']) have a look at [link1](https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide) and [link2](http://articles.adamwrobel.com/2010/12/23/trigger-adwords-conversion-on-javascript-event) – artm Sep 02 '14 at 12:55