Skip to content

Instantly share code, notes, and snippets.

@cowboy
Forked from paulirish/utmstrip.user.js
Created May 20, 2011 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/983747 to your computer and use it in GitHub Desktop.
Save cowboy/983747 to your computer and use it in GitHub Desktop.
userscript: Drop the UTM params from a URL when the page loads
// ==UserScript==
// @name UTM param stripper
// @author Paul Irish
// @namespace http://github.com/paulirish
// @description Drop the UTM params from a URL when the page loads.
// @extra Cuz you know they're all ugly n shit.
// @include http://*
// ==/UserScript==
// save this as utmstrip.user.js and drag it into Chrome or Firebug (with greasemonkey)
var oldUrl = location.href;
var newUrl = oldUrl.replace(/\?([^#]*)/, function(_, search) {
search = search.split('&').filter(function(v) {
return !/^utm_/.test(v);
}).join('&');
return search ? '?' + search : '';
});
if ( newUrl != oldUrl ) {
window.history.replaceState({}, '', newUrl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment