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:

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

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

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.


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


Comments are closed.