Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-30-2011, 03:22 AM   PM User | #1
Inersha
New Coder

 
Join Date: Jun 2008
Posts: 50
Thanks: 18
Thanked 0 Times in 0 Posts
Inersha is on a distinguished road
Adding Tracking To Outbound Links

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:

Code:
$(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?
Inersha is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:28 PM.


Advertisement
Log in to turn off these ads.