August 23, 2022
How to Remove FBCLID from Google Analytics 4?
When I am writing this blog post, Google Analytics 4 does not have a native method to easily remove unwanted URL query parameters. As a result, your reports might look something like this:
See all those fbclid=xxxx? They make your reports harder to read, and if the same page was visited by multiple users from Facebook, that page would be displayed as different/unique pages.
That is why excluding query parameters is useful.
In this blog post, I will explain how to remove fbclid from Google Analytics 4 reports and make your data cleaner.
Sure, you could use a dimension called Page path (that does not contain query parameters), but maybe I want to analyze data including *some* query parameters. I just don’t want to see those parameters that pollute my reports, including fbclid.
What is FBCLID?
Every time a visitor clicks any link on Facebook that redirects him/her to your website, Facebook adds an additional parameter to the URL, called fbclid. FB uses that to keep tracking you as you navigate across websites.
Despite the privacy issues, another drawback of this method is that your analytics reports get polluted because every link for every visitor will have a unique fbclid value. This means, that the same page/URL in your reports will be reported as multiple unique pages.
Since GA4 at the moment (when I am writing this blog post) does not have the built-in feature, we are going to use Google Tag Manager to exclude URL query parameters. This means that your GA4 also must be installed with GTM.
Login to your Google Tag Manager web container’s interface and go to Templates.
Then click Search Gallery in the Variable templates section.
Find the template that is called Trim Query. It was created by Ayudante, a Tokyo-based consulting and mobile software development company. Big thanks to them!
Click Add to workspace and then Add.
Create a variable that excludes query parameters
By using the aforementioned custom template, let’s create a variable. Go to Variables > New > Variable configuration and select “Trim Query” as a variable type.
Select Page URL as a Target URL (because this variable will take the Page URL and will remove certain parameters). Keep all other settings as they are.
Note: this variable does not actually affect the page URL that your visitors see in the browser address bar. It will just return a cleaner URL as a value, and we will use it in GA4 tag(s).
Now we need to include fbclid in that list. In the screenshot below, I have added more than one but in the context of this article, the fbclid is a must. One row = one parameter that should be excluded.
Save the variable. I usually name it Page URL excluding unwanted query parameters.
Update the GA4 configuration tag
When Google Analytics 4 is implemented, it automatically tracks things like page_location. But you can overwrite that. In the GA4 configuration tag that you should already have (if not, read this guide), add a new parameter page_location and set the aforementioned custom variable as its value.
Save the tag.
Is GA4 installed on a single-page application? Then I would suggest setting the same page_location parameter in all GA4 event tags as well.
Save your changes.
Test the setup
It’s time to test if everything is working properly. Click the Preview button at the top right corner of the GTM interface (to enable the Preview mode).
Then enter the URL of your website and also include several query parameters that you have excluded. You can also include some parameter that should still be displayed in the reports. All query parameters should be connected with &. Example: yoursite.com?fbclid=12345&xyz=888. Click Connect.
Once your GA4 tags have fired, go to Google Analytics > Configure > Debugview. Find your device, check the most recent events, and check if their page_location value does not contain the excluded parameters.
If everything is working fine, publish your GTM container by clicking the SUBMIT button and then completing all the other necessary steps.
What if you use GTAG?
Then take a look at this documentation. Your developer will need to write some custom code that sends the page_location parameter in the gtag code (without unwanted URL parameters). And your role here could be to prepare a list of unwanted parameters that should be later excluded by a developer.
Also, tell the developer that in the future, that list might be updated, and he/she will need to include those updates in the code.
Remove FBCLID from Google Analytics 4: Final Words
Will Google Analytics 4 offer a built-in feature to exclude query parameters? I hope so. Maybe when you are reading this guide, that feature is already available (in that case, please let me know in the comments. Maybe I just forgot to update this article 🙂 ).
But the lack of a built-in feature does not mean we cannot solve it ourselves. With this workaround, you can still have cleaner URLs in GA4 reports.
Keep in mind that this implementation will apply only to future data. Your historical data will still contain those unwanted URL query parameters.
Also, one more thing for those who use Google Analytics 4 to send the data to their server-side endpoint and then send it to Facebook Conversions API. If you are doing this, then the method I have explained should NOT be used; otherwise, fbclid will not be sent to FB.