How to Remove utm_source & Other Parameters From Your URLs

Cat cleaning its mouth with her tongue.

How to add gay porn to any site

These days it’s a quite common and very annoying habit by a few services to attach utm_source and other so called parameters to your Internet address aka URL. It’s not only that.

Basically anybody can add anything as a parameter to your website address

and make it appear as if it’s part of your blog or site. Outrageous isn’t it? Just try adding

  • “?content=gay,porn”
  • “?utm_source=ISIS”
  • “?you-suck”

to any of your URLs or other sites’ URLs. Most sites accept that without even showing an error “not found”.

In case you link such an URL Google will even index it.

This way you can make Google show up fake pages that do not even exist on other people’s websites.

Unwanted parameters can break a lot of things on your site. You get unlimited duplicate content this way. Everybody can meddle with your address using parameters.

People share the wrong (polluted) links. Thus you lose juice on social media. Links can even break because of the added parameters. In the best case they are just confusing.

 

Who adds utm_source to your URLs and why?

utm_source is added by multiple services in order to track performance in Google Analytics. You get inflated numbers on Google Analytics though. That’s why

I do not recommend adding such parameters in the first place.

When I click a link on Facebook which is tagged utm_source=Twitter.com it gets wrongly counted as stemming from Twitter and not Facebook. It is still tagged as Twitter.com even though you shared it on Facebook.

Also public social media counts often do not add up anymore. An address with added parameters will get counted as different than the original link.

You can prevent Buffer and other social media automation and tracking tools from adding the utm_source crap.

That’s not enough to remove all other unwanted parameters from your address though. Thus I wrote this tiny script in JavaScript you can add to your WordPress blog anywhere in the header:

 

How to remove all unwanted parameters?

This is the actual script I used for years on my blog here. Then I had to remove the script from my site as it seems WordPress 3.6+ redirection interferes with it. I’m not even sure. Nobody could help me explain that.

This way spammers who bombarded my blog with requests created countless invisible additional pages. Remove yours too in case you use WordPress and the same issue appears.

For most people the “additional pages” problem will stay invisible though even if it happens. I only discovered it because Google optimization experts found thousands of links from my blog on their link profile using advanced tools.

I still use this script successfully on my custom built statics website.


<script language="JavaScript" type="text/javascript">
<!--
var url = self.location.href;
var p = url.indexOf("?");
var str = url;
var parameter = str.slice(p);
if (p >= 1 && parameter.indexOf("p") != 1 && parameter.indexOf("s") != 1)
{
url = str.slice(0,p);
self.location.replace(url);
}
//-->
</script>

I know it’s quite redundant and not very elegant but my JavaScript skills haven’t been used much in the last decade so you are welcome to customize it.

The script basically checks where the parameter starts and removes everything from the URL including the question mark “?”

which signifies the start of the parameters. It then redirects visitors on the client-side to the accurate URL without parameter crap in the address.

In the end people end up on the actual address they should end up from the start. Don’t let someone else prevent them from reaching their destination by polluting the URL with parameter spam.

The only acceptable parameters are the “p” so that you can still use the post preview function in your WordPress and “s” for the search function.

 

Are there better solutions by now?

When you added the script to your site already a link like this one should get redirected: http://example.com/?you-suck
to the clean address instead.

You can actually still try it on my main website: http://onreact.com/?you-suck

Also take note that I have elaborated on the topic of utm_source crap in a more recent post.

There I link to two more sophisticated solutions. I use both of them, one locally on my Firefox browser and another on this blog here.

They aren’t perfect either though. They just remove utm_source crap but not all other types of polluting parameters. That way the gay pron would still show up in your address.

Last updated: March 30th, 2017.

 

Merken

Merken

Merken

Merken

Merken