Editor’s Note: Clean Up URLs and Remove Tracking Parameters with URL Cleaner is part of the MacStories Starter Pack, a collection of ready-to-use shortcuts, apps, workflows, and more that we’ve created to help you get the most out of your Mac, iPhone, and iPad.
Picture this:
You’ve just come across an interesting article or product you want to share with someone, so you copy the URL and you’re ready to send it over iMessage, tweet it, link it on your site – you name it. Then, you notice that the URL has a bunch of ugly tracking parameters appended to the end of it. I’m sure you’ve seen them too: it’s those ?utm
and soc_src1
and similar strings of text that some web publishers rely on to monitor where traffic is coming from and track other parameters about clicked URLs. For a publisher, those bits of data can actually be useful; for the end user, however, I’ve always wished there was an easy way for apps or extensions to “clean up” URLs and return the vanilla version of a link without any tracking parameter attached.
So, for the debut of our MacStories Pack event, I decided to fix the problem myself with a shortcut I appropriately called URL Cleaner. With this shortcut, which you can download for free at the end of the story and find in the MacStories Shortcuts Archive, you’ll be able to instantly remove popular tracking parameters from any URL and get a “cleaned up” version of it copied into the system clipboard. Best of all, URL Cleaner has been specifically optimized for iOS, iPadOS, and macOS, taking advantage of desktop-specific actions in macOS Monterey all while remaining integrated with the share sheet and Siri on iPhone and iPad.
Let’s take a look.
Behind the Scenes of URL Cleaner
First of all, I should give a shout out to friend of MacStories and developer Robb Knight, who released an app called TrackerZapper a few months ago. TrackerZapper is a free utility that sits in your Mac menu bar and removes tracking parameters from links you copy. Given that TrackerZapper is open source, I wondered if I could turn its core feature into a shortcut that worked on all platforms where the Shortcuts app is available. So, following Robb’s kind permission, I was able to take TrackerZapper’s built-in list of well-known tracking parameters, expand it with a few additions, and turn it into a regular expression for Shortcuts that quickly removes all matched parameters from URLs.
I designed URL Cleaner to be used in a variety of ways. At its most basic level, you can run URL Cleaner manually in the Shortcuts app or from the Home Screen widget on iOS/iPadOS. In that case, the shortcut will try to find a URL you’ve already copied to the clipboard. If no URL is found, you’ll be asked to enter one manually. The latter option is more useful on macOS, where you may have copied a URL to the clipboard a while back, so it’s not the most recent item in your clipboard history anymore, but you can still get to it with a clipboard manager (I’ve been trying Raycast for that lately, and I like it).
URL Cleaner can also receive a URL as input from the share sheet (on iPhone or iPad) or from another shortcut, which means you can use URL Cleaner as a headless, drop-in function of other shortcuts. If you often find yourself dealing with URLs in your shortcuts and want to make sure they’re always “clean” URLs with no tracking parameters attached, here’s what you can do: in your shortcut, use the ‘Run Shortcut’ action and select URL Cleaner as the shortcut you want to run as a function; then, make sure the input of this action is the URL you want to clean up. When the shortcut runs, it’ll invoke URL Cleaner in the background, which will process the URL, copy a cleaned version of it to the clipboard, and pass it as output back to the original shortcut. I’ve started using URL Cleaner as a function in dozens of my shortcuts, and I love it.
I also want to point out how I’ve optimized URL Cleaner for macOS Monterey with a new technique that brings some additional intelligence to Shortcuts.
On Monterey, Shortcuts offers an action called ‘Get Current URL from Safari’ that can read the URL of the Safari tab that is currently active. I wanted to use this action so that you could trigger URL Cleaner from the menu bar or with a hotkey to clean up the URL of the Safari tab currently open. The problem is that the action fails if a) Safari is closed or b) you don’t use Safari as your Mac browser to begin with. To circumvent the issue but retain the convenience of this action, I added an AppleScript step that checks whether or not Safari is open; if it is, the shortcut runs the ‘Get Current URL from Safari’ action; otherwise, it ignores the Safari action and tries to fetch URLs with the methods I described above.
I plan to explore this technique more in depth in the next Automation Academy lesson for Club MacStories Plus and Premier members, which will be all about advanced tips and techniques for Shortcuts on macOS Monterey. Essentially, Shortcuts for Mac lacks a built-in action to check if a particular app is running; because AppleScript can do it though, it was easy enough to drop in a script that checks for Safari’s status and passes back a response.
Regardless of how you run URL Cleaner, the result at the end will always be the same: you’ll get a notification that displays the cleaned URL, which will also be copied to the clipboard so you can paste it elsewhere.
I should also note that, if you want, you can modify URL Cleaner by adding more tracking parameters that should be removed from URLs. To add more parameters to URL Cleaner’s default list, just enter a single pipe character |
and the tracking parameter you want to remove in the ‘Text’ action at the beginning of the shortcut, as pictured below. You can repeat this process with as many parameters as you want and URL Cleaner will still run in a couple of seconds.
So that’s URL Cleaner. It’s a genuinely useful shortcut I’ve been using for the past few weeks, both as a standalone utility and as part of other shortcuts as a function I can execute in the background. It only felt appropriate to share URL Cleaner as the first shortcut for the MacStories Starter Pack, but stay tuned: I have lots more to share through the rest of the week.
URL Cleaner
Clean up URLs by removing tracking parameters from them. The shortcut supports a built-in list of widely known tracking parameters (courtesy of Robb Knight), and can be easily expanded to remove more tracking parameters from URLs.
You can follow the MacStories Starter Pack on our hub, or subscribe to the dedicated Starter Pack RSS feed.