jQuery, Thickbox and Google Analytics

Today I had to find some way to track the links within a page using Google Analytics, jQuery and Thickbox. With the new ga.js it is pretty straight forward:

[sourcecode language='javascript']
$(function(){
if(typeof(pageTracker) != ‘undefined’) {
$(‘a.thickbox, area.thickbox, input.thickbox’)
.click(
function(){
pageTracker._trackPageview(
$(this).attr(‘href’)
);
}
);
}
}
);
[/sourcecode]

Related posts

  1. jQuery Plugin for using default value as label
  2. Thickbox 2.0 released featuring gallery functionality
  3. Rewrite and log links with jQuery
  4. jQuery Form Validation as Smarty Plugins

6 thoughts on “jQuery, Thickbox and Google Analytics

  1. Pingback: rdmey

  2. Pingback: jquery  - empfohlen von anderen | oneview.de - Dein Online-Gedächtnis

  3. Pingback: [Sedna RSS] jQuery.info

  4. Sorry I’m new to Javascript implementation.

    I wanted to know where would you insert the above mentioned code. I assume in the header and if so then we need to add the other script from Google Analytics above this code or after this code.

    Thanks in advance.

    Regards,

    Pali Madra

    • Actually, this code will run when the page is ready for interaction, and I would be pretty sure that adding this script to the head and leave Google Analytics code at the bottom (where the most people put the analytics script) will make it work 99% of the time. If someone clicks the thickbox link before the page is ready for interaction this script may miss to register. For a fool-proof solution, you probably have to load the analytics code in the head and then add a script inline to each and every anchor you would like to track, but that is an ugly solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>