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:

$(function(){
	if(typeof(pageTracker) != 'undefined') {
		$('a.thickbox, area.thickbox, input.thickbox')
			.click(
				function(){
					pageTracker._trackPageview(
						$(this).attr('href')
					);
				}
			);
		}
	}
);


No related posts.

This entry was posted in JavaScript and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted July 18, 2009 at 4:15 am | Permalink

    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

  2. Mattias Hising
    Posted July 18, 2009 at 9:53 am | Permalink

    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.

3 Trackbacks

  1. By rdmey on December 26, 2007 at 10:40 pm

    Google Reader Shared Items The evil of dropdown, flyout and pop-up menus (GUUUI – The interaction designers coffee break)Google Analytics(ga.js), <b>jQuery</b>, Thickbox and Stats(Google Blog Search: jquery)IE 8 now doesn’t trip on Acid (Ajaxian)Analyzing Timer Performance (John Resig)DOM Assistant updated to 2.5, adds CSS selector support (456 Berea Street)Theme Firefox On-the-Fly with Personas [Featured Firefox Extension]

  2. [...] mit: Liste, List, jquery, SCREENshots, PlugIns, übersicht merken bewerten Google Analytics(ga.js), jQuery, Thickbox and Stats – The Frontend Du hast leider keinen oder keinen aktuellen Flash-Player installiert. Du kannst den aktuellen [...]

  3. By [Sedna RSS] jQuery.info on February 1, 2008 at 2:20 am

    [...] 19:35Google Analytics(ga.js), jQuery, Thickbox and Stats – The Frontend – garycannone del.icio.us/tag/jquery — Analytics(ga.js) Frontend Google Stats The Thickbox and jQuery [...]

Post a Comment

Your email is never published nor shared. 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>