Stripping URL query parameters with an iOS shortcut to reduce tracking

Overview

Query parameters in URLs are sometimes useful, but often they are not. For example, shared Twitter links have additional tracking information that have no functional advantage when sharing. They can be removed manually when sending a link to someone, but that time accumulates. To automate this I created an iOS shortcut to remove them when a link is in the clipboard to reduce the privacy impact.

iOS Shortcuts

Shortcuts is an iOS app that allows to combine actions on iOS without having to create standalone iOS apps. The interface is simple enough that it can be used from a phone while creating useful tools. The API is powerful, even something as simple as links directly into iOS settings can be a time saver. In previous iterations the application was known as Workflow, and since iOS 13 Shortcuts are available as app installed by default.

Implementation

Links shared from Twitter have the following format:

https://twitter.com/(twitter-account)/status/(tweet-id)?s=...&t=(tracking-id)

In this case none of the query parameters serve a function other than tracking. Treating the URL as a string stripping parameters is simple enough - keep everything before ? and discard the rest. Conveniently iOS Shortcuts let us access the clipboard just like that, no parsing of the URL is necessary in this case.

For me this was the first time I used iOS shortcuts and I have to say that it is surprisingly easy to use. We can pull data from the clipboard and apply regex directly to it, we match for content pre-question mark in URLs and write the match back to the clipboard - if any. Since this URL pattern is not limited to Twitter I made the script remove all query parameters regardless of host. Instagram, Amazon and others similarly use query parameters merely for tracking. My shortcut is available here but it should be simple to reimplement manually.

Addendum

After putting this together I learned that iOS 17 will support such functionality natively, no shortcuts required. This is a great feature and I’m glad it will arrive natively in iOS to boost user privacy a bit.