Skip to content

Instantly share code, notes, and snippets.

@Lomanic
Forked from paulirish/utmstrip.user.js
Last active November 7, 2018 23:08
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 Lomanic/cf1158a9bfb90d8b5dbbb4d05483e857 to your computer and use it in GitHub Desktop.
Save Lomanic/cf1158a9bfb90d8b5dbbb4d05483e857 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, Sam Hasler, Lomanic
// @namespace http://github.com/paulirish
// @version 1.3
// @description Drop the UTM params from a URL when the page loads.
// @extra Cuz you know they're all ugly n shit.
// @include /^http.*\?.*[?&]utm_.*$/
// @run-at document-start
// @updateURL https://gist.github.com/Lomanic/cf1158a9bfb90d8b5dbbb4d05483e857/raw/utmstrip.user.js
// @downloadURL https://gist.github.com/Lomanic/cf1158a9bfb90d8b5dbbb4d05483e857/raw/utmstrip.user.js
// ==/UserScript==
// Update:
// In chrome, it's better to just install the UTM stripper chrome extension:
// https://chrome.google.com/webstore/detail/google-analytics-paramete/jbgedkkfkohoehhkknnmlodlobbhafge
// It is great and open source: github.com/mihaip/utm-stripper
// You can also install this greasemonkey script if you really want.
// download this script. go to about:extensions. Turn on developer mode and drag and drop
// this file onto the window. it'll install it. hopefully.
// lastly, if your site / marketing funnel uses these tracking tokens. you can clean up your users URLs
// look at the comments below on correct installation to integrate with __gaq.push
if (/utm_/.test(location.search) && window.history.replaceState){
var oldUrl = location.href;
var search = location.search.substr(1).split('&').filter(function(v){
return !/^utm_/.test(v) && v;
}).join('&');
search = search ? '?' + search : '';
var newUrl = location.protocol + '//' + location.hostname + location.pathname + search + location.hash;
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