Page 1 of 2
If you have ever gotten really serious about a Google AdWords account, then you have definitely spent some time setting up AdWords Conversion Tracking. Conversion tracking is so essential to effectively managing an AdWords account that I won't run one without it. In the standard case, it is very easy to setup, you create a conversion, paste the code into your page and you're done. Unfortunately things don't always work out that easily. What if your conversion isn't defined by viewing a page, what if it's downloading a PDF, watching a video, clicking an affiliate link, etc? That's where things get a little bit trickier. I almost lost a client due to my demand of conversion tracking, and that is what forced me to figure out how to track conversions without displaying a "thank you" page.
This article will take you through the process that I use to track conversions using onclick events. Note: the method I prefer relies on jQuery. (Let's face it jQuery really does let you write less and do more). If you would like to learn how to track AdWords Conversions on click events WITHOUT jQuery, then skip to the end of this article to see that snippet of code.
To start out with, let's take a look at the default AdWords Conversion Tracking Code:
<!-- Google Code for Contact Page Conversion Page -->
/* <![CDATA[ */
var google_conversion_id = XXXXXXXXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = " XXXXXXXXXXXX";
var google_conversion_value = 0;
/* ]]> */
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/XXXXXXXXXXXX/?label=XXXXXXXXXXXX&amp;guid=ON&amp;script=0"/>
The code here is pretty straight-forward, you set some variables so that Google knows that type of conversion pixel to display, things like ID, colors, labels, etc. Then you call a script from one of Google's domains which takes the variables you just set and displays a conversion pixel (and the little privacy notification if you selected that option when you created the conversion). The trick here is that you can just call a function when someone clicks on your download link to track that download as a conversion in AdWords, because you have to actually call that "conversion.js" from Google's server in order to get it to track.
If you take a look at the <noscript> part of the AdWords Conversion Script, you'll see that all it does is display an image, with a source URL that uses the same 'google_conversion_id' and 'google_conversion_label' from the traditional script. With that in mind, we can track conversions just by displaying an <img> with the right URL in the source. Pretty simple, right? OK, so on to the code.