简体   繁体   中英

How to add Google AdWords Conversion Tracking code in knockoutjs button click event?

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.

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!

var s = document.createElement("script");
s.type = "text/javascript";
s.src = "google code";

document.head.appendChild(s);

Or

document.body.appendChild(s);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM