Remove Google Analytics cruft from your URLs
This is a jQuery code snippet I use on my site to remove the cruft that Google Analytics when someone links to a page from a campaign:
if (window.history && history.replaceState && (location.search.match(/utm_/) || location.hash.match(/utm_/))) {
search = location.search.replace(/(\?|\&)?utm_[a-z]+=[^\&]+/g, '');
hash = location.hash.replace(/(#|\&)?utm_[a-z]+=[^\&]+/g, '');
history.replaceState({}, '', location.pathname + search + hash);
}
This removes GA query strings and hashes after the request has been logged by your web server and before your readers bookmark the page.
Hope that helps.
Written by Gregory Pakosz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Html
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#