Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple Greasemonkey Script to remove "utm_source" parameters from the browser address bar. This is not "perfectly" cool as it needs to reload the page but it helps to prevent that you spread those "utm" parameters in links or bookmark it on accident. It tries to be smart about how it reloads (only the top frame in a frameset) and what it remov…
// ==UserScript==
// @name Remove-UTM-from-URL
// @namespace http://oderwat.de/gmscripts/remove-utm-from-url.js
// @description Removes UTM from url (by reloading)
// @version 1.0
// @include *
// @run-at document-start
// ==/UserScript==
var loc = window.top.location.toString();
if(loc.indexOf('utm_')!==-1){
window.top.location.replace(loc.replace(/[?&]utm_([^&])+/g,''));
}
@SamHasler

This comment has been minimized.

Show comment
Hide comment
@SamHasler

SamHasler Nov 29, 2016

Why not put utm in the @include, you won't need the if then.

// ==UserScript==
// @name           Remove-UTM-from-URL
// @namespace      http://oderwat.de/gmscripts/remove-utm-from-url.js
// @description    Removes UTM from url (by reloading)
// @version        1.0
// @include        /.*\?.*utm.*/
// @run-at document-start
// ==/UserScript==

window.top.location.href = window.top.location.href.replace(/[?&]utm_([^&])+/g,'');

SamHasler commented Nov 29, 2016

Why not put utm in the @include, you won't need the if then.

// ==UserScript==
// @name           Remove-UTM-from-URL
// @namespace      http://oderwat.de/gmscripts/remove-utm-from-url.js
// @description    Removes UTM from url (by reloading)
// @version        1.0
// @include        /.*\?.*utm.*/
// @run-at document-start
// ==/UserScript==

window.top.location.href = window.top.location.href.replace(/[?&]utm_([^&])+/g,'');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment