Tidy URL Bookmarklet

This simple bookmarklet strips ugly Google Analytics Tracking parameters from the URL of the currently viewed web page. Uses history.replaceState if available to avoid the need for a page reload.

Example

Before:

http://boingboing.net/2012/02/16/mountain-lion.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+boingboing%2Fgadgets+%28Boing+Boing+Gadgets%29

After:

http://boingboing.net/2012/02/16/mountain-lion.html

To install

Drag this link Tidy URL to your browser bookmark bar. Click as required.

On your iOS device, copy and replace the url of an existing bookmark with this:

Unencoded

JavaScript used in a bookmark must be URL encoded. Hence the gibberish. For the curious, this is the plain code:

(function(){
	var tidyurl = window.location.href.replace(/utm_(term|content|source|medium|campaign)=[^&]+&?/g, "").replace(/\??$/g, "");
	if (history.replaceState) {
		history.replaceState(null,'',tidyurl);
	} else {
		window.location = tidyurl;
	}
})();

Thanks John Gruber for the handy URL encoding JavaScript bookmarklet builder script for BBEdit.

Oliver Boermans is a design geek in Adelaide, South Australia: ollicle.com is a place for Ollie to rant, reflect and share. Feed