Facebook fbclid pollution -- can it be prevented?

AI-generated summary

A discussion about Facebook’s fbclid parameter causing issues with Discourse permalinks. MiG shares that when a Discourse permalink is shared on Facebook and someone clicks it, Facebook appends the fbclid parameter, resulting in a 404 error on Discourse. MiG attempts to use the Permalinks Normalization setting to remove the fbclid parameter but is unable to create the correct regex.

rmens also experiences issues with fbclid polluting Google Analytics data. MiG finds a temporary solution using a Cloudflare page rule to remove the fbclid parameter before it reaches Discourse. simon investigates the issue and suggests that the problem lies with the redirect from the shortened permalink to the actual topic URL.

MiG eventually uses the Permalinks Normalization setting to remove the fbclid parameter, but not before sharing their temporary Cloudflare solution. simon and riking discuss the expected behavior of query parameters in Discourse permalinks, and justin confirms that Permalinks Normalization is the correct feature to use in this case. MiG requests an example of how to use the Permalinks Normalization setting to remove the fbclid parameter.

So I really love the permalinks feature of Discourse.

For example, I’ve been collecting photos and videos at https://fortmactech.com/riverbreak – which forwards to the longer URL of the actual topic.

The problem I’m running into is that when that’s posted on Facebook and someone clicks it, Facebook appends its fbclid crap at the end. So the URL is something like:

https://fortmactech.com/riverbreak?fbclid=IwAR1E9PoBxuWURZRJlA4D0VrnESbfjGfC2xKuvVJzCRUmIJy7ZRKMkkH8I-U

And it generates a 404 on Discourse.

Is there a trick to getting Discourse to ignore the fbclid parameter?

So I think this is something that can probably be done with the Permalinks Normalization setting, but I can’t figure out the regex. Basically remove anything after and including ?fbclid= I think.

Interested in this too. This is polluting our Google Analytics data.

So I’ve been able to solve it with a Cloudflare page rule:

Screen Shot 2021-04-14 at 9.27.33 AM

But would rather do it at the discourse level instead.

How are you forwarding https://fortmactech.com/riverbreak to https://fortmactech.com/t/river-drone-videos-photos-2021/818?

It seems that adding query parameters to the topic URL doesn’t cause any issues. For example, this should work: https://fortmactech.com/t/river-drone-videos-photos-2021/818?fbclid=IwAR1E9PoBxuWURZRJlA4D0VrnESbfjGfC2xKuvVJzCRUmIJy7ZRKMkkH8I-U. So the issue is somehow related to the redirect that’s in place for https://fortmactech.com/riverbreak.

I’ve sort of solved it now by using Cloudflare. I have turned off the Cloudflare page rule for a while if you want to see the 404 happening.

Try this link as an example:

https://fortmactech.com/riverbreak?fbclid=IwAR1E9PoBxuWURZRJlA4D0VrnESbfjGfC2xKuvVJzCRUmIJy7ZRKMkkH8I-U

 

I added it like this in admin / settings / permalinks:

Screen Shot 2021-04-14 at 10.30.21 AM

 

This is what it looks like once it’s added:

 

 

And the result is this:

 

I’ve tried with a trailing slash as well.

If I do the Cloudflare Page Rule to remove the fbclid stuff before it hits Discourse, then it works just fine.

Is this what the Discourse “Permalinks Normalization” is for? Would I be able to strip out anything after ? using that setting?

Thanks for the details. It seems that query parameters break Discourse permalink redirection. I’m not sure if that is expected to happen.

It’s definitely expected, it’s heavily used for permalinks that have e.g. forum.php?topic_id=1234.

That makes sense. Is there a way to “transform” an incoming URL before it’s analyzed by the permalinks code? Is that the “Permalinks Normalization” feature?

Yes that’s exactly what permalink normalizations is for :smiley:

Can someone give me an example of how I would get rid of ?fbclid= and anything after it, using the Permalinks Normalization setting? Thanks :slight_smile: