Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google AdWords Conversion Tracking with AJAX form [duplicate]

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!

like image 285
infinity2k9 Avatar asked Feb 10 '10 22:02

infinity2k9


3 Answers

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

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

like image 144
Brian D'Astous Avatar answered Nov 12 '22 09:11

Brian D'Astous


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.

like image 30
Edgar Griñant Avatar answered Nov 12 '22 09:11

Edgar Griñant


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.

like image 1
Kethatril Avatar answered Nov 12 '22 09:11

Kethatril