Here’s the thing. You’re browsing on the internet and find an interesting website that you want to share with a friend.

You tap on a share button and copy the website’s URL. Suddenly you realize that the URL contains pesky UTM parameters.

Urchin Tracking Module (UTM) parameters are five variants of URL parameters used by marketers to track the effectiveness of online marketing campaigns across traffic sources and publishing media.1

As a self-respecting friend you’re – you quickly remove those from the end of the URL before you share it with your friend.

iOS Shortcuts

I knew about the app2 for a while, from the times when it was called Workflow3 but I never gave it a proper chance until today. While I was browsing through the gallery of all the available shortcuts I came up with an idea …

Automate all the things

There’s a large set of actions supported in Shortcuts. The big deal however is the ability to run JavaScript on a web page.

Since the URL polluted with UTM parameters looks like this:

https://www.example.com/page?utm_content=buffercf3b2&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer

I came up with a solution in JavaScript that would remove all the query parameters associated with the UTM from the URL:

const params = new URLSearchParams(location.search)
const utm_params = ['utm_content', 'utm_medium', 'utm_source', 'utm_campaign', 'utm_term']

utm_params.forEach(item => {
	if (params.has(item) === true) {
		params.delete(item)
	}
});

if (Array.from(params).length === 0) {
	completion(`${location.origin}${location.pathname}`)
} else {
	completion(`${location.origin}${location.pathname}?${params}`)
}

Complete shortcut:

Part 1 Part 2
Shortcuts1 Shortcuts2

As a last step, I’ve enabled the shortcut in the Share Sheet so it’s easily accessible:

Shortcuts1 Shortcuts2

Sorry marketers

Usage workflow is following:

  1. You’re viewing web page in Safari
  2. Tap on share button
  3. Tap on Remove UTM button
  4. Copy or share the sanitised URL

You can download the shortcut here. As a prerequisite you need to enable setting for Untrusted Shortcuts.

Do you use Shortcuts app? Which shortcuts are your favourite ones? Do you know any other tricks? Let me know on Twitter!