Skip to content

Instantly share code, notes, and snippets.

@IronistM
Last active December 11, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronistM/4622399 to your computer and use it in GitHub Desktop.
Save IronistM/4622399 to your computer and use it in GitHub Desktop.
/*
* Instructions: Place *after* the Google Analytics Snippet,
* so this _gaq.push executes after the _gaq.push(["_trackPageview"]); call.
*/
_gaq.push(function() {
if (window.history && history.replaceState && location.search.match(/utm_/)) {
var query = {};
location.search.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) {
if (! ($1).match(/^utm_/)) {
query[$1] = $3;
}
});
var newstate = (function(val) {
var s = [];
for (var key in val) {
if (val.hasOwnProperty(key)) {
s.push(key + "=" + val[key]);
}
}
return location.pathname + ((s.length) ? "?" + s.join("&") : "");
} (query));
if (document.cookie.indexOf("__utmz=") != -1) {
history.replaceState({},
"", newstate);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment