Tracking URL referer in Google Analytics using #

Google Analytics v2.0 by vrypan.

When you need actively to track where your visitors are coming from – say because you are running several campaigns – you need to now where your visitors are coming from. No, seriously, it DOES matter. 🙂

The “normal” way to do this is to add some parameters to the URL. Like e.g. myrurl.com/?track=siminar_url 
The downside of this is that the URL then is seen as a new URL by the seach engines (Google in short). This triggers dublicate contect filters since you can basically find the same stuff on 2 or more different URLs.

One solution is to use the new canonical tag : https://webhaj.boostme.dk/canonical-tag-state-your-canonical-url/

But an easier one is to use the # (called hash or pound sign), since this is basically seen as an internal link on the same page and the seach engines therefore just ignores this!

To have Google Analytics track these you need a little hack provided by Avinash Kaushik. Use this JavaScript:

var pageTracker = _gat._getTracker("UA-12345-1"); 
// Solution for domain level only
pageTracker._trackPageview(document.location.pathname + "/"
+ document.location.hash); 
// If you have a path included in the URL as well 
pageTracker._trackPageview(document.location.pathname
+ document.location.search + "/" + document.location.hash); 

Read more on: http://janeandrobot.com/post/URL-Referrer-Tracking.aspx – scroll down to “URL Fragment”

And: http://www.seomoz.org/blog/whiteboard-friday-using-the-hash

Leave a Reply

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