Google AdWords Conversion Tracking with AJAX form

24,011

Solution 1

Use an IFRAME to call an HTML file with the conversion tracking code on it.

http://www.benjaminkim.com/?p=24

Solution 2

AFAIK the best way to do it in your scope is using the no-script image.

I will show you 2 ways:

  1. You can put it on your "thank you HTML" as is, with escaped characters where necesary.

  2. Or... Just put an empty image tag like this anywhere on your HTML document:

    <img src="" width="1" height="1" style="visibility:hidden;" alt="" id="myconversion" />
    

    Then add this line of jQuery to your script before or after the your "thank you HTML":

    $("#myconversion").attr("src","xxxxxxxxx");
    

    Where xxxxxxxxx is the src attribute of the no-script image.

Solution 3

I have heard that the iframe method is unreliable. Dynamically inserting the script does work however as the conversion script uses document.write you have to do something like this http://www.webdeveloper.com/forum/showthread.php?t=195112 to load the script otherwise it doesn't work.

Share:
24,011
infinity2k9
Author by

infinity2k9

Updated on May 30, 2020

Comments

  • infinity2k9
    infinity2k9 almost 4 years

    I have a google adwords conversion tracking code that I need to implement basically on an onclick event. The form I am tracking submits information using AJAX and then renders a Thank you message to the page by replacing the form's div with the thank you HTML ( $('div').html("thank you....., etc"); )

    I'm wondering if there's a way to a) trigger a conversion track when the SUBMIT button is clicked, or b) if I include the google script to be posted to the site in the html() function that writes to a div, will that track the conversion? or c) Any other thoughts on doing this?

    I've searched a bit on this but haven't had much luck.... Thanks!