Remove the dirt Facebook makes on your website URL

🗑️ A basic and useful JavaScript code!


Remove the dirt Facebook makes on your website URL


We have already published once about an extension that removes several gets from any website that dirty your url: Clean your URLs from Social Network Parameters and Others.

But, today we’re going to show you how to use a basic JavaScript script to remove Facebook’s fbclid from your website.

Something like this:

https://website.com/index.html?fbclid=IwZXh0bgNhZW0CMTEAAR0-qJHl1VErGqub7nFOmL9OOuFJFJsdnr5yg9xEZA2T1Cc29buSBeBVfzc_aem_qxWU50NfOPAeOYePO2TlzA

This filth that Facebook does, besides being HORRIBLE 🤮, is also disturbing:

  • When you save the URL in favorites, sometimes it is already saved, but as these codes are dynamic, you end up saving a URL that is already there several times;
  • It also disrupts the site’s statistics services, such as Google Analytics, for example, duplicate occurrences appear.

Not to mention that this only serves as tracking for them.

To remove, add this code below, before the closing </head> tag:

<!-- REMOVE fbclid -->
<script>
 const url = window.location.href
 if(url.match(/fbclid/)){
 const new_url = url.replace( new RegExp("\\\?fbclid.*","gm"),"")
 history.pushState({}, null, nova_url);
 }
</script>

Then just test and no more dirt!

A quick and useful tip for many.

See too:


javascript web


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles