Skip to content

Remove tracking data from copied URLs

A while back, my friend James and I were discussing the amount of tracking cruft in many URLs. In my case, I subscribe to a ton of email newsletters, and I noticed that those URLs are just laden with tracking information—and most go through a URL processor, so you don't really see those tracking details until you've clicked the link, at which point it's too late to avoid any tracking.

I wanted a way to clean up these URLs such that the least-possible tracking information was sent to a server—and in particular, to prevent any browser cookie creation. In addition, if I want to share a link with friends, I don't want to send them a crufty tracker-laden link—I wanted a nice clean shareable URL.

Note: I wrote all of this before I knew about Jeff Johnson's Link Unshortener, which does all of this (and more) in a "real" app. If you'd like the easy solution, Jeff's app is the way to go. Mine is definitely a do-it-yourself concoction that's not for the faint of heart.

tl;dr version: Install this macro group (v8.3) in Keyboard Maestro to remove tracking details from copied URLs in a set of defined apps.

Latest Update: Apr 11 2022 Fixed a bug related to custom domains, added aliexpress as a decrufting URL, and updated the in-app help boxes.

Going forward, all future updates to this macro will be found in this post on the Keyboard Maestro forums.

As an example, here's a URL from a recent Monoprice email newsletter. (Note: I changed a few of the characters so these URLs will not work; they're for demonstration purposes only.) Any tracking data is completely disguised in the source URL; all you see is a jumble of letters and numbers at the end of the URL:

http://enews.emails.monoprice.com/q/LLMxJBmP1xo0XEpHXEE5PmLbqHbNxpVsuheZcOJcm9iZ0Bnc3ltZnN3ZWIuY29tw4gZyWuu1KtfpSL58gax3zGue2fhqQ

When loaded in the browser, all of that resolves to a completely different URL:

https://www.monoprice.com/product?p_id=11297&trk_msg=8OLJJ72Q87O4PCIC9HC71NL7VS&trk_contact=T3KPNYKTNJTD6NU53HNJCDD7T4&trk_sid=FGHVB9JP6L3MVLERLES7DLEFEG&trk_link=9HBDB7KBCAEKT949P8P8JQG5J4&cl=res&utm_source=email&utm_medium=email&utm_term=View+product+recommended+for+you&utm_campaign=210902_thursday

Fairly obviously, everything after p_id=11297 is simply tracking information, so the actual URL is just:

https://www.monoprice.com/product?p_id=11297

Ideally, that's the URL I'd like to load and/or share with friends, not the tracking-laden version. One weekend, I decided to do something about it, and sat down with Keyboard Maestro to work on a solution, thinking it wouldn't be overly complicated...

Months later, I think it's finally reached a point where it's shareable, and the 24 macros in my URL Decrufter group show that it was, indeed, overly complicated. But it's done now, and working quite well.1To extract destination URLs from disguised source URLs, that URL has to go to the server, which means tracking information is sent. However, my macro uses curl to do that, so it's not happening within a browser where cookies could then be set.

Here's how it looks in action…

The features and limitations of my macro are as follows…

  • Obviously, you'll have to have Keyboard Maestro to use the macro.
  • The macro only works on copied links—clicked links aren't modified. Why not? Because capturing mouse clicks and analyzing the clicked item would require "real" programming, instead of a relatively straightforward macro that acts on the clipboard contents. I actually prefer it this way, because I can use a simple click if I don't mind delivering the tracking information, or a right-click and Copy Link when I don't want to share.
  • The macro only works in apps that I define. If the app isn't part of the defined set, then no processing occurs. This is easily changed by modifying the listed apps in the URL Decrufter macro group.
  • The macro only works on a defined list of hosts—it doesn't attempt to capture and interpret every link I copy. This was a design decision, as I didn't want the overhead of processing every copied link, and I have a limited number of known domains that send me tracking-laden URLs.
  • It can take anywhere from a few tenths of a second to a couple of seconds to process a copied URL. Nearly all of this time is during the curl step, which translates the original disguised destination URL into the actual final URL, which is then stripped of its tracking details.

For more on this macro, please read this forum post on the Keyboard Maestro forums—it's where I'll post any future updates, as it's too complicated to update this blog post over time.

13 thoughts on “Remove tracking data from copied URLs”

  1. Anyway to avoid popup for youtube which has a ? mark as part of the basic URL. Not sure what a URL with a referral looks like. Or maybe it's there and I'm missing it

    1. I do have one for (1), but it's basically too simple to post, so here's how to make it. It's a single if-then macro:

      If condition: The Decrufter is enabled
      Then condition: Disable macro The Decrufter
      Else condition: Enable macro The Decrufter

      Basically toggles it from whatever state it's in to the other state. (Mine also displays a notification so I know which state it's presently in.)

      For (2), do you mean the list of URLs it's decrufted? By default, it only keeps the last 50, and you can see tham at any time by opening KM's prefs, selecting the Variables tab, and browsing the d_p_trimmedURLs variable. (Better: Copy-paste it to a larger text editor window.)

      Someday, I may do more with the history data, but not sure when.

      -rob.

    1. Sorry about that, typo in the URL—it should work now. (download > downloads)

      -rob.

Comments are closed.