Stripping surveillance parameters from Facebook and Google links

While largely opaque to most users, Facebook and Google massage any links that you acquire on their sites to include data used to track you around the web. This script attempts to strip these surveillance parameters from the URL’s. It is by no means all-inclusive. Imaginably, there are links that I haven’t yet encountered and that need to be considered in a future version. So consider this a proof-of-concept.

The problem

For example, I performed a Google search1 for “Smarties”. Inspecting the first link - to Wikipedia, I see:

What is all this garbage? Just give me the Wikipedia link.

Similarly, with Facebook, here’s a representative link from a post shared by a friend:[0]=AT0wPBsJAwDQs1I3A-IE7zqQqBiwEHA3kJW9oLxfh04m_WvjBdWOcmz-6vYfoSNsdLLYxRWgAKZw3ExnMZ2CUH-0nRSmILzqTmumL68oL5-OcChT8pbK11VBSHVG1nt64-Ek8S1AESqn8nYCjZ-gI80uo3Hhd8UJyvOD-KoZ3yI_M5Gfcdu1

Again, garbage that exists only so that Facebook can follow me around the web and generate behavioural data that they can use in turn against my better interests and those of society at large.

After the sanitization process below, we have:

Nice and tidy with only what is needed to route me to the desired link without unnecessary tracking data.


The solution is to strip out the cruft with which surveillance capitalists corrupt the web. I’ve applied this script as a Keyboard Maestro but it could be reconfigured with ease as a macOS text service. Or the same idea could be implemented in other OS flavours.


sub urldecode {
    my ($rv) = @_;
    $rv =~ s/\+/ /g;
    $rv =~ s/%(..)/pack("c",hex($1))/ge;
    return $rv;

sub urlencode {
    my ($rv) = @_;
    $rv =~ s/([^A-Za-z0-9])/sprintf("%%%2.2X", ord($1))/ge;
    return $rv;

# remove referral parameters
sub strip_utm {
    $_ = shift @_;
    # eliminate duplicate & from the stripping process
    # clean up
    return $_;

my $original_url = $ARGV[0];
# my $original_url = $ENV{KMVAR_unsterile_link};

# decode the url as needed
my $url_text = ($original_url =~ m/%3A/) ? urldecode($original_url) : $original_url;
# fix links from Facebook
if ( $url_text =~ m/l\.facebook\.com/ ) {
    # strip the actual link
    $url_text =~ m/http[s]?.*l.facebook.*?u=(.*)/;
    print strip_utm($1);
else {
    $_ = $url_text;
    # deal with google referrals
    if( m/http[s]?:.*google\.com\/url\?/ ) {
        print $1;
    else {
        print $_;

Next steps

  • Strip Amazon referral links - yes, I know some people monetize their blogs in whole or in part using Amazon referral links. I don’t care. If bloggers want to make money that way, then develop relationships with smaller commercial entities, those that support and live in their local communities and treat their employees with dignity.
  • Strip Twitter links - Deal with links from the seething cauldron of hate and incivility that is Twitter.

  1. Ordinarily I don’t use Google services at all, even for search. But I did for this example. ↩︎