Friday, March 14, 2014

Google AdWords Event Based Conversion Tracking

If you've ever implemented AdWords, you've probably dropped a conversion tracking snippet in your code that looks like this:

<!-- Google Code for Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "12345678-123-123456";
var google_remarketing_only = false;
/* ]]> */
<script src="//" type="text/javascript">
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//;guid=ON&amp;script=0"/>

This works great for success or landing pages, much like simple URL based goals in Analytics. However, just like Analytics, simple URL based goal/conversion tracking doesn't always cut it. Analytics offers Event tracking to allow more control over tracking goal conversions (even automatically).

So what about when you need to track AdWords conversions more programmatically though? For example, tracking a link click as an AdWords conversion. Luckily, the AdWords conversion logic makes this easy. See the <noscript> part of the tracking snippet? Typically the most useless part of the code, this is actually our lucky break. Throw in some jQuery and you've got event based AdWords conversion tracking! I also threw in some Analytics event tracking for good measure (the _gaq.push() portion).

$(document).ready( function() {
  $("#conversionLink").click( function() {
    $('body').append('<br /><div style="display: inline;"><img alt="" height="1" src="//;guid=ON&amp;script=0" style="border-style: none;" width="1" /></div>');
    _gaq.push(['_trackEvent','Conversion Link', 'Conversion Link Click']);

No comments:

Post a Comment