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

May 24, 2022

Exclude URL Query Parameters in Google Analytics 4

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

When I am writing this blog post, this feature is not available by default in Google Analytics 4. 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 that you might want to consider excluding.

 

Video tutorial

If you prefer video content, here’s a tutorial from my Youtube Channel.

 

Table of contents

– Hide table of contents –

  • Why are URL query parameters a problem?
  • 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

 

Why are URL query parameters a problem?

URL query parameters are not bad by nature. In fact, they are very useful. 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 clearly see in Google Analytics reports, that this was a successful form submission. That’s useful.

But there are also many URL parameters that 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 just 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).

 

Identifying URL query parameters that you want to exclude

First, you need to identify what URL query parameters should be excluded. If you are migrating from Universal Analytics (GA3), the process if pretty simple. Go to Admin > View settings and find the list of all parameters. We will use it later.

If you are setting this up from scratch (but you already have installed GA4 on a site + collected data for a while), you will need to build 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 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 list all the query parameters. Take the list that you have 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.

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 Preview button at the top right corner of the GTM interface (to enable the Preview mode).

Then enter 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.

 

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).

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

  • gtm_debug (Google Tag Manager)
  • fbclid (Facebook)
  • 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 to do that maintenance, there’s an alternative. You can exclude all query parameters except the ones that you want to use.

For that, there is a white list feature in the Trim Query template.

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 historic data will still contain those unwanted URL query parameters.

 

Julius Fedorovicius
In Google Analytics Tips
17 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

Luan
  • Jun 6 2022
  • Reply

Hi Julius!

Great content!

I am using Universal Analytics and some of my Google Ads campaigns have "keyword" and "idcampaign" parameters. These parameters are not excluded from my page reports in UA, creating unique URLs according to "keyword" and "idcampaign" values. Should I delete them in the "Exclude URL Query Parameters" field?

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

      Inge
      • Jun 13 2022
      • Reply

      Hi Julius, thanks! I managed to exclude the fbclid parameter from GA4 reports only. Just wondering, does this affect the attribution in the source/medium reports? Or does Google only check the referrer instead of the URL parameters for source/medium attribution?

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.

          Claas
          • Jun 21 2022

          Thank you, for your replies Julius. This helps a lot. Keep up the good work!

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

David Peake
  • Jun 25 2022
  • Reply

Hi Julius,

I tested excluding the Google Click ID parameter using this method, but it caused "google / cpc" tracking in GA4 to completely stop working.

I don't think anyone running Google Ads campaigns with auto-tagging enabled should exclude the gclid parameter.

    Julius Fedorovicius
    • Jun 25 2022
    • Reply

    Yes, I mentioned that in this blog post.

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
  • RSS feed
Recent Posts
  • Google Analytics 4 User ID for cross-device tracking: how to configure it
  • 23 Key Benefits of Google Analytics 4
  • 10 Google Analytics 4 Mistakes in Configuration You Should Avoid
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings