...

View Full Version : jQuery Adding Tracking To Outbound Links



Inersha
03-30-2011, 04:22 AM
I want to add tracking to my outbound links for Google Analytics using jQuery. The outbound links are sent through a redirect in a directory called "visit".

So far, I've got this script:



$(document).ready(function(){

$("a[href*='/visit/']").click(function(){

pageTracker._trackPageview('$(this).attr('href')');

});

});


This seems almost perfect (do I not need to escape any inverted commas?), as it sets the virtual pageview as the link in the href. For example, if the link is pointing to a redirect in the folder /visit/website-a/, the pageview gets set as /visit/website-a/ too.

However, throughout the site I've used a combination of absolute and relative links, so I have links that look like this:

../visit/website-a/
../../../visit/website-a/
/visit/website-a/
visit/website-a/

...and so on. How can I make it so that jQuery sets the page tracker in the format "/visit/website-a/" every time? Any ideas?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum