Facebook - remove tracking url

Remove the tracking parameter in links

< Opinie na Facebook - remove tracking url

Ocena: Słaby - skrypt nie działa

§
Napisano: 22-04-2023

Tested in Facebook Messenger at URL https://www.facebook.com/messages/t/1705799802805701
This link was sent in chat: https://www.cafemorville.dk/menukort/frokost/
F12 the URL and got: https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.cafemorville.dk%2Fmenukort%2Ffrokost%2F%3Ffbclid%3DIwAR1OW6dQbtdzLkl4q-wfIpPhyEAzKrYOwtYPZETbN7rV5fDJ9ISIC30IBDc&h=AT3Q3OtUhtNpk-QzLGACP9I6-7cQI02jJUSXW_0UK5lpaNWV_QIOnHosftbimgIoSQJpyRC_b9p_t8bldx6PW98VCDh5W3LD0wTIrI4woGl6ma6UCM2A9ikHo9Lpiv4nZ52zlg

So both the fbclid and l.facebook.com/l.php remains.


I made som modifications to the script, but it seems that Facebook checks their elements and recreates them if they have been modified.

Here are my modifications:

function fix(u) {
let url = new URL(decodeURIComponent(u.substr(3)));
// Remove garbage keys https://greasyfork.org/en/scripts/30111-remove-junk-url-parameters/code
let params = url.searchParams;
if (params.get("wpsrc") == "socialedge") {
params.delete("wpsrc");
}
for(var key of params.keys()) {
switch (key) {
case "tse_id":
params.delete(key);
continue;
case "fbclid":
params.delete(key);
continue;
}
if (key.startsWith("utm_")) {
params.delete(key);
}
}
return url.href;
}

if (t=location.search) {
let s=fix(t);
if (s!=t) history.replaceState(null, null, (s || location.pathname)+location.hash);
}

function fixL(L) {
let i=0, a, j=0;
for (;a=L[j];j++) {
if (a.LnkFixed || !a.href) continue;
if (a.protocol && a.protocol.startsWith('http') && a.host.includes('facebook.com') && a.search) {
let s=fix(a.search);
if (a.href != s) a.href=s;
}
a.LnkFixed=1;
}
}

AchernarAutor
§
Napisano: 23-04-2023

This script is not intended to remove fb redirects. It removes some parameters ("_cft_" & "_tn_") from fb (internal) links.
I've written it at the request of someone who was already using a similar script for another site.


Have you tried this script?
https://gist.github.com/k-barton/6af2dfb466a1f2b69e37

Odpowiedz

Zaloguj się, by odpowiedzieć.