• Courses
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login

March 28, 2025

Exclude URL Query Parameters in Google Analytics 4

Updated: March 28th, 2025

In Universal Analytics (GA3), a feature called “Exclude URL query parameters” allowed you to remove unwanted parameters from the URLs and have cleaner reports.

When I wrote this blog post, this feature was not available by default in Google Analytics 4 (there’s data redaction, but it’s not a complete replacement for “Exclude URL query parameters”). But there is a workaround that I will explain in this article (it involves Google Tag Manager). If you are using GTAG, I will briefly give you some directions at the end of this tutorial.

Also, at the end of this blog post, I will share a list of the most common URL parameters you might want to consider excluding.

 

Video tutorial

If you prefer video content, here’s a tutorial from my YouTube channel.

 

Table of contents

Here’s what you will learn in this article

  • Why are URL query parameters a problem?
  • Why is the GA4 Data Redaction feature not enough?
  • Identifying URL query parameters that you want to exclude
  • Custom template
  • Create a variable that excludes query parameters
  • Update the GA4 configuration tag
  • Test the setup
  • What if you use GTAG?
  • Popular query parameters you might want to exclude
  • Final Words
Subscribe and Get the Ebook - conversion tracking handbook

 

Why are URL query parameters a problem?

URL query parameters are not bad by nature. They are handy. For example, if someone submits a form on a page, they might be redirected to a page example.com/signup?success=true.

Since the success=true query parameter is in the URL, we can see in Google Analytics reports that this was a successful form submission. That’s useful.

But many URL parameters give no direct benefit to us in the GA reports. They are important for other tools (like Linkedin Ads, Facebook, Mailchimp, etc.), but they bring no value to analysis in GA.

For example, if a visitor lands on your website from Facebook, the page URL will contain an additional parameter fbclid. So instead of seeing mysite.com/pricing in your reports, you will see mysite.com/pricing?fbclid=sdfghjkluytresvbjk4567890dcvb. If another visitor comes to your site, he/she will see a different fbclid value in the URL – mysite.com/pricing?fbclid=ihgvefb98yg3ebfji8y3hefnk.

Even though both users landed on the same /pricing page, Google Analytics will show these as two unique URLs in the reports. That applies if you use dimensions such as Page path + query string or Page Location.

FB uses fbclid to track visitors.

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 don’t want to see those parameters that pollute my reports, like fbclid, _hsenc, mkt_tok, mc_cid, etc.

That’s where the “Exclude URL query parameters” feature is useful. You remove what’s unwanted while you still keep important query parameters (such as success=true from the previous example).

 

The Process

Here is the process for how you can exclude URL query parameters in GA4:

  • Step #1: Identify URL query parameters
  • Step #2: Import a custom template in GTM that will exclude parameters
  • Step #3: Create a variable that will exclude URL query parameters
  • Step #4: Update Google Tag and GA4 event tags
  • Step #5: Test the setup

Now, let’s take a closer look at every step.

 

Why is the GA4 Data Redaction feature not enough?

Data redaction if better than nothing. That’s for sure. But it’s not ideal to exclude unwanted URL query parameters. Let me illustrate. You have three URLs of the same page:

  • example.com/contact
  • example.com/contact?fbclid=123
  • example.com/contact?xyz=true

It’s the same page, but you see three unique rows in your GA4 report.

If you use GA4 Data Redaction to redact fbclid and xyz, then your report will show the following URLs:

  • example.com/contact
  • example.com/contact?fbclid=(redacted)
  • example.com/contact?xyz=(redacted)

See the problem? You still have three unique URLs in your reports. But if you implement what I explain in this article, you will see just one URL: example.com/contact.

Subscribe and Get the Ebook - working with reports in ga4

Identifying URL query parameters that you want to exclude

First, you need to identify what URL query parameters should be excluded. That can be done with a custom report. Go to Explore > Blank.

Import Page path + query string (or Page location) dimension by clicking the Plus icon here:

Then, import Views in the Metrics section.

If you want to learn more about Free Form Exploration reports, read this.

Now, double-click both on the dimension and on the metric. This will add them to the “Rows” and “Values” sections of the Variables tab.

Filter down the report to show only those URLs that contain any query parameter. This means that Page Path + Query String must contain a question mark.

In the “Filters” section, add a filter with the following condition: Page Path + Query strings contains ?

Now you have the report of URLs where any query parameter is present.

Select to show more rows and write down the parameters you no longer wish to see.

That list will be later used in this blog post.

 

Custom template

Since GA4 does not have the built-in feature at the moment (when I am writing this blog post), we will use Google Tag Manager to exclude URL query parameters. This means that your GA4 also must be installed with GTM.

Log in 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 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 remove specific parameters). Keep all other settings as they are.

exclude query parameters in google analytics 4

Note: this variable does not affect the page URL visitors see in the browser address bar. It will return a cleaner URL as a value, which we will use in GA4 tag(s).

Now we need to list all the query parameters. Take the list you prepared in the chapter “Identifying URL query parameters that you want to exclude”. And list those items one by one. One row = one parameter that should be excluded.

Important: you might be tempted to lowercase the value of this variable:

Don’t do that if you are running Google Ads and you are importing conversion data from GA4. Lowercasing the page_location will also affect the value of the gclid parameter (which is case-sensitive). If you lowercase the URL, your Google ads attribution won’t work.

Save the variable. I usually name it Page URL excluding unwanted query parameters.

Subscribe and Get the Ebook - Mastering GA4 event tracking

Update the Google Tag and GA4 event tags

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.

Also, include this parameter in all GA4 event tags in your Google Tag Manager container. You can either manually include it in each tag…

… or you could create a GA4 event settings variable, insert and manage the page_location parameter there, and then use that event settings variable in all GA4 event tags. This will be more convenient in the long run because if you ever need to make any change in the settings variable, all GA4 event tags will inherit those changes (if, of course, those tags use that variable).

To configure this, first go to Variables > New > Google Tag: Event Settings and enter the following configuration:

If you already have a Settings Variable, then update it (instead of creating a new variable). Save the variable.

Then edit all your GA4 event tags to use that settings variable:

 

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 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 > Admin > 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 must write custom code that sends the page_location parameter in the gtag code (without unwanted URL parameters). Your role here could be to prepare a list of unwanted parameters that a developer should later exclude.

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.

Subscribe and Get the Ebook - 20 GA4 mistakes

 

Popular query parameters you might want to exclude

I have a little bonus for you. Some URL parameters are common and popular among multiple websites so it can be a good practice to exclude them beforehand (even if you don’t see them now in your GA4 reports).

This list (in no particular order) is not definitive, but it can help:

  • gtm_debug (Google Tag Manager)
  • fbclid (Facebook). Important: if you use GA4 events to send data to the server-side GTM endpoint and then send it to Facebook Conversions API, then do not exclude fbclid.
  • mc_cid (Mailchimp)
  • mc_eid (Mailchimp)
  • __s (Drip)
  • __hssc (HubSpot)
  • __hstc (HubSpot)
  • __hsfp (HubSpot)
  • _hsenc (HubSpot)
  • _ke (Klaviyo)
  • hsCtaTracking (HubSpot)
  • igshid (Instagram)
  • ml_subscriber (MailerLite)
  • ml_subscriber_hash (MailerLite)
  • msclkid (Microsoft)
  • omnisendContactID (Omnisend)
  • s_cid (Adobe)
  • ef_id (Adobe)
  • twclid (Twitter)

 

Alternative: excluding all query parameters except what you allow

The solution that I have just explained requires occasional maintenance. This means that maybe, in the future, new query parameters will appear in your reports, and you will need to exclude them, too.

If you don’t want that maintenance, there’s an alternative. You can exclude all query parameters except those you want to use.

For that, the Trim Query template has a white list feature.

Here, you should enter only those parameters that you want to see. Everything else will be removed.

But be careful with this. If someone in the future adds some important query parameter to your website (or maybe Google Analytics 4 starts using some new important parameter), it will not be included in the reports/tracking.

Here are the parameters that you should always add to this variable (if you use the whitelist):

  • utm_medium, utm_source, utm_campaign, and all other parameters listed here
  • gclid
  • dclid
  • _gl
  • _ga

 

Exclude URL Query Parameters in 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 is to send the data to their server-side endpoint and then send it to the 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.

 

Julius Fedorovicius
In Google Analytics Tips
48 COMMENTS
Marin
  • May 24 2022
  • Reply

Hi Julius, if I'm using serverside tagging, should I exclude this on client side GA4 tag and it will transfer URL's to serverside GA4?

    Julius Fedorovicius
    • May 24 2022
    • Reply

    Yeah, why not

Tim Heicks
  • May 31 2022
  • Reply

Hi Julius, great post as always. Thanks a lot!

Just one question: Your solution would also impact the 'page_location' in the raw data synced with BigQuery, right? Do you know a way to only strip the url query params in the GA4 UI but not in the raw data? I really hope Google will make it possible once they add it on their end.

    Julius Fedorovicius
    • Jun 10 2022
    • Reply

    No workaround for that. Once parameter is excluded, it is excluded from everywhere

Inge
  • Jun 10 2022
  • Reply

Hello Julius, I am using server side tagging and a GA4 data stream for Facebook Conversions API. If I exclude facebook parameters for GA4, should I do this in the server side GA4 tag instead of the web GA4 config tag? I don't want the fbclid in the GA4 reports but I assume I still have to send it at least to the server, so that Facebook does not lose the parameters? Thanks!

    Julius Fedorovicius
    • Jun 10 2022
    • Reply

    Correct

Claas
  • Jun 20 2022
  • Reply

Hi Julius,

Thank you for the interesting information. A question that I was not able to answer 100% from the article and the comments so far: With client-side tracking using this method, is the URL query cut off before the data enters the system? What does this mean for campaign tracking, for example with MicrosoftAds or FacebookAds in the respective systems? Does it still work there? If I understand it correctly, the assignment to source/medium in GA4 should still work if I didn't remove the umt tags.

    Julius Fedorovicius
    • Jun 20 2022
    • Reply

    If you are using GA4 to send data to FB CAPI too, you should not exclude it then. This workaround excludes parameters before they are event sent to the system.

      Claas
      • Jun 20 2022
      • Reply

      OK thank you. One last question for understanding: The assignment to the sources in GA4 is not done first-hand via the queries (e.g. fbclid)? Theoretically, what would happen if an access were made from a Facebook ad click that also did not contain any utm parameters. Would Analytics still be able to assign this click to the appropriate source? To put it the other way round: If I were to filter out the fbclid, would I definitely have to use utm parameters so that a page view or a conversion is still assigned to the source Facebook?

        Julius Fedorovicius
        • Jun 20 2022
        • Reply

        GA4 does not care about fbclid. What matters is UTMs. If UTMs are not present, your FB traffic will be attributed to referral and facebook.com

        If you exclude fbclid but you use GA4 tags to send data to sgtm and then fb capi, FB will have harder time attributing conversions of its ads.

Lori
  • Jun 22 2022
  • Reply

Hello Sensei Julius,

a quick question about this. I have a few queries that I would like to remove. I can do that with your solution really well. Do you know another way to remove a query if it has a certain value? An example: I have a query named "p" if it contains the value "p=1" I would like to remove it. If it has another value then not.

Do you have any idea how this could be done?

Would be very happy to hear from you, am a big fan of your work.

    Julius Fedorovicius
    • Jun 22 2022
    • Reply

    You would need to write custom javascript code for that

Rob Leslie
  • Jul 8 2022
  • Reply

I had hoped to use this to exclude certain URL query parameters that GA4 automatically uses to fire the event view_search_results (q,s,search,query,keyword). Right now, a third-party tool that runs on our site is using the "s" query parameter for something other than searches, which means that view_search_results is getting triggered when it shouldn't. Using "Trim Query" effectively removes the query parameter from page_location, but it doesn't seem to affect whether GA4 fires view_search_results -- that must still be being processed based on the URL itself.

Can you think of anything else I could try to address this?

Thanks for the helpful guide. It was still helpful for me in cleaning up my URLs. (I hate that GA4 doesn't have this built in like Universal Analytics.)

    Charlotte
    • Apr 14 2023
    • Reply

    I have the same problem. Any idea Julius Fedorovicius?

      Julius Fedorovicius
      • Apr 14 2023
      • Reply

      Just remove the "s" query parameter from the Enhanced measurement site search settings if "s" in your case is not related to site search.

Marin
  • Sep 7 2022
  • Reply

Hi, can I use this to exclude UTM parameters also? In case I need to have GA4 without those if someone decides (privacy team) that way?

    Julius Fedorovicius
    • Sep 7 2022
    • Reply

    You can exclude any URL parameter you want

Brad
  • Sep 21 2022
  • Reply

How would you treat a URL with (seemingly) multiple query parameters?

e.g. /?p=3116377&preview=true&_thumbnail_id=3116380

Am I correct in interpreting that 1) p 2) preview and 3) _thumbnail_id are all QPs?

If so, do I need to add each one of them to a "delete query key" row in the variable?

Thanks

    Julius Fedorovicius
    • Sep 21 2022
    • Reply

    Yes and yes

datalocks
  • Oct 5 2022
  • Reply

Hey,

would this apply to Landing Page as well? Your example shows data in Explore reports, would this also impact the standard reports e.g Pages & Screens?

Thanks

    Julius Fedorovicius
    • Oct 5 2022
    • Reply

    It affects all reports

Stephen
  • Oct 10 2022
  • Reply

This is very helpful. Instead of overwriting the page_location, could this be altered to write to a custom dimension, such as page_location_clean?

    Julius Fedorovicius
    • Oct 11 2022
    • Reply

    sure

    Adam Pawaskar
    • Feb 26 2024
    • Reply

    Thanks Stephen for asking this question. I had same query as I too think we should not overwrite any existing tracking and enable tracking altered values to new Dimensions.

    Thanks Julius for answering this question.

Bryan
  • Jan 20 2023
  • Reply

Hi Julius,
is gtm debug not used to filter developer traffic? What if we remove this parameter?

    Julius Fedorovicius
    • Jan 20 2023
    • Reply

    no. nothing will happen.

Suzy
  • May 18 2023
  • Reply

Hi Julius,

I'm struggling to find more information on parameters that SHOULD NOT be excluded. Could you please elaborate a little so that I can better understand why should we should not exclude the dclid, _gl, and _ga parameters?

If these should not be excluded, are there any alternatives to create cleaner reports? I see someone suggested to create a custom dimension for page_location_clean. Would you recommend this as a solution? Thank you.

    Julius Fedorovicius
    • May 19 2023
    • Reply

    Parameters like dclid are necessary for ad tracking to work properly. page_location_clean might be an option if you don't have more than 500 unique values per day. Otherwise, you will get high cardinality issues.

    Another option is to use two dimensions in the same report: Page path and Hostname.

      Suzy
      • May 19 2023
      • Reply

      Thank you for your reply. What about why we shouldn’t excluded _ga and _gl? I actually excluded these in GA3 and now thinking if my data has been wrong this whole time 😱

        Julius Fedorovicius
        • May 19 2023
        • Reply

        Exclusion in GA3 is not a problem. They are excluded in GA3 after the data has been processed. In GA4, excluded cross-domain tracking parameters might cause tracking problems and cross-domain tracking can break.

Nick Guebhard
  • Jun 1 2023
  • Reply

Thanks for that Julius. It's a useful variable template. One suggestion is to also exclude the parameters from the page_referrer, particularly if you are using this to exclude PII.

    Julius Fedorovicius
    • Aug 3 2023
    • Reply

    Good suggestion, thanks

Carmen
  • Jun 22 2023
  • Reply

Hey Julius! Thanks for the solution!

I've followed the steps and I can see it working on the GTM preview. However, when using the Debug Mode in GA4, I can still see the query parameters I'm trying to exclude. Wondering if you know why this may be happening?

    Julius Fedorovicius
    • Aug 3 2023
    • Reply

    Something is configured incorrectly. But it's impossible to tell what without seeing the setup.

Milena
  • Jul 25 2023
  • Reply

Hi, Julius,

I just have one question - can I use the page_location parameter twice in my tags, because my website is a SPA website and I already use page_location parameter to detect {{dlv – pageUrl}} >> (following your instructions for implementation with a developer's help - analyticsmania.com/post/single-page-web-app-with-google-tag-manager/ )

So, now I will have defined the following event parameters for my event:
1. page_path - {{Page Path}}
2. page_location - {{dlv – pageUrl}}
3. page_title - {{dlv – pageTitle}}
4. page_location - {{Page URL excluding unwanted query parameters}}

I just to make sure that this setting won't brake something :D

Thank you!
BR,

    Daven
    • Aug 3 2023
    • Reply

    is your developer sending the Full URL with Query Params in {{dlv_pageUrl}} usually with SPA page urls they strip everything off anyways.

    But to answer you question you can only set the page location once. so what you would need to do is use the {{dlv-pageUrl}} as your target URL when creating {{Page URL excluding unwanted query parameters}}

Wes
  • Sep 13 2023
  • Reply

Thanks Julius, I've followed this and had it implemented for some time now. I can confirm that it does function as described in the post.

One catch though. Even though the excluded parameters do not appear in the "page_location" parameter in the debugger, they are still appearing in the "Landing page + query string" dimension in reports.

I'm a little stumped on how these parameters are getting through.

And just to rule them out
- yes the setup is live in the published GTM container
- and yes my reporting views are only showing a time frame since the settings were published

Any suggestions? My only guess is that GA must be populating the "Landing page + query string" dimension from a different parameter.

marcelo araujo
  • Sep 20 2023
  • Reply

hi, nice exposition.
i need to make the inverse:
get / generate in GA4 the all urls with parameter, like an eg ?id=1234, but to easy view, get the 'title' instead of "id".
its is possible? to make a custom report with this config?
Tks a lot!

Rob
  • Oct 6 2023
  • Reply

Thanks Julius for the great blog. Very helpful.

Have you tested removing _gl parameter? I used trim query to remove _gl because it was making the reports hard to read, and I still see cross domain working fine. You suggested we should always keep this in the URL. Have you tested cross domain tracking when _gl is removed from the URL?

Many thanks!

Kelly
  • Oct 11 2023
  • Reply

what if I have already set up pageview event tag with {{window.location.href}} as the value for the page_location parameter. Would it cause conflict to have the above setup in the config tag and my current setup in the pageview event tag?

Kelsie
  • Nov 1 2023
  • Reply

Just wanted to note, and it might be helpful to include:
I orginally was sending this as not the page_location and as a custom event page_location_short and this is where the event collection limits come in. When I was checking my data, it kept getting cut off, leading me to think i set up the variable wrong in GTM. Turns out, since it is not the predefined page_location (which GA4 limits to 400 characters) that it was only allowed 100 character and therefore it was getting cut off too soon.

Looks like in order to do this I will need to use the predefined event, page_location in order to get this data since almsot all of my custom URLs will be over 100 characters.

Mahjabeen
  • Feb 20 2024
  • Reply

Thank you for this Julius, its exactly what I needed. However my Google tag is already reading page_location from a custom js variable which is sanitising the URL of any PII data (I followed instructions at https://www.goinflow.com/blog/remove-pii-from-google-analytics).
Can I specify all the PII related parameters (such as name, email) etc. in the Trim Query custom template?

gabriel
  • Aug 21 2024
  • Reply

Why you exclude fbclid but not the gclid?
Thanks

    Julius Fedorovicius
    • Aug 21 2024
    • Reply

    Because Google ads was linked to Google Analytics and gclid id was necessary for that integration.

Matt
  • Apr 29 2025
  • Reply

Hi Julius -
Great work, as always.

As this is an old post, I'd like to check-in to see if there are newer options in GA4 to address this issue with parameter URLs? I am curious if GA4 Data Filters would be an option to exclude parameter URLs from reporting? Lastly, is it safe to assume that your solution would work at the API level as well? We are currently using GA4 data in another platform via API and we are having issues due to the excessive amount of parameter URLs.

Kathy C
  • May 14 2025
  • Reply

Hi Julius,
Thanks for the info around this option.

I am not clear on one thing... My problem is that in the GA4 page title + screens report the gtm_debug page views are being counted along with the production pages. They are only visible if I set the table to page path + query for the dimension and then filter for gtm. Naturally I don't want these "junk pages" counted in my page views. Will pages with page location changed to strip out gtm (but are still test pages and not production pages) still be counted in pages title + screens as page views? Basically, secretly counting junk pages in with the real pages?

Belen
  • May 28 2025
  • Reply

Hi Julius,
Thanks for the post and the workaround. However, the "Trim Query" template is not available anymore on GTM gallery. Could you suggest any other solution for the query issue?
Thanks in advanced!

    Julius Fedorovicius
    • May 28 2025
    • Reply

    I just checked the gallery and the template is still there. Please check carefully again. You are looking for a custom variable template, not custom tag template. And this search must be done in a web GTM container, not server container.

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *


 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Conversion rate in Google Analytics 4
  • Google Tag Manager Data Layer Explained
  • Cross-domain tracking in Google Analytics 4
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings