One of the great things about Google Analytics, is how easy it is to track your incoming traffic. And if you’re running an email campaign, or pushing some other outside link source, you can use their link builder to create a query string that tracks the individual sources and campaigns. (See their tool here.)
However, the only problem with this is that if you’re encouraging social sharing at the destination URL, those query strings can cause problems. Facebook sees them as unique pages, and twitter sharing looks ugly. So, I found this solution that quickly and easily cleans up the URL for social sharing, while maintaining the tracking from the query string.
Basically, just add the following code below your _trackPageview
call.
if (window.history && history.replaceState && location.search.match(/utm_/)) {
_gaq.push(function(){
history.replaceState({}, "", location.pathname); //assuming you want no query string
});
}
This was originally posted at Stack Overflow here.
http://stackoverflow.com/questions/934119/track-campaigns-with-google-analytics-without-query-string-parameters