How to Exclude URL Query Parameters in GA4

There are cases when you must exclude URL query parameters in Google Analytics 4. Unlike Universal Analytics, excluding URL query parameters in Google Analytics 4 can’t be done using filters. So, this article will show you two ways to do it: GA4 “Redact data” feature and Google Tag Manager.

Why you should remove URL Query Strings in GA4 

As mentioned above, there are cases when you need to remove URL query strings (or parameters). To mention some of them:

  • Some of your website page URLs have sensitive personal information such as full name, email, phone, etc. When you add the GA4 configuration code, GA4 will collect these URLs. Since sending such information in GA4 is forbidden, your property can be blocked or deleted. As a solution, you can use the approach below to delete this sensitive information from URLs. 
  • Some URLs have query strings that are unique almost for every website visitor. Due to that, Google Analytics 4 started to show “(other)” in your reports. This phenomenon is called “cardinality” and negatively influences your analytics opportunities. Therefore, you can use the solution mentioned in this article to avoid cardinality. 

Although this is not a complete list of situations to consider removing URL Query parameters, they are the most common ones. They will definitely require you to do something to resolve them. 

One of the solutions is to remove some parameters, but how to understand which ones to remove and which ones to leave? 

How to determine the parameters to delete

In some cases, it can be challenging to understand which parameters to delete and which to leave for future analysis. There is a rule I follow when I clean URL query parameters for my clients. 

I leave all UTM parameters that can be recognised by Google Analytics 4. For instance, “fbclid” (facebook ads) can’t be recognised by Google Analytics 4. Therefore, I delete it. However, “utm_source” can be read correctly. Therefore, I don’t delete it. 

In general, you shouldn’t delete the following UTM parameters tracked by GA4 by default:

  1. UTM source
  2. UTM medium
  3. UTM campaign
  4. UTM content
  5. UTM term
  6. UTM campaign id 
  7. UTM source platform
  8. UTM marketing tactic
  9. UTM creative format 

If there are other query parameters to track, such as order_id, search terms or something else, I remove them from the URL. 

If some parameters are necessary for future analysis, I group them and send them via event properties. When you group them, you avoid having a cardinality issue in Google Analytics 4. If you can’t group them significantly, consider not registering them as custom dimensions in Google Analytics 4 and sending them into BigQuery instead. This way, you can analyse this data in BigQuery without having a cardinality issue in GA4.

How to exclude URL Query parameters from the URL

Of course, after you clarify what URL query parameters you want to delete and leave, it’s time to configure it. Let’s start with the first variant, the one that doesn’t require any other tool except Google Analytics 4.

Excluding URL Query parameters using GA4 “Redact data” feature

Google Analytics 4 offers a native solution to remove unnecessary URL query parameters. It’s called “Redact data”. The feature itself offers two options by default:

  • It can detect and delete email addresses from event data automatically. It’s activated by default for all GA4 properties created since September 27, 2023.
  • You can provide URL query parameters to remove from the event properties, and it will replace the unnecessary URL parameter values with “(redacted)”.

Let’s explore how to activate this feature step by step:

Step #1: Open GA4 and navigate to Admin -> Data Streams ->Web Stream Details and select “Redact data”

Navigate to GA4 Data Redact
Navigate to GA4 Data Redact

Step #2: Configure Redact Data:

  1. If you want to remove email addresses only, activate “Email” section
  2. If you want to remove other query parameters, activate “URL query parameters” and provide them into the field (for instance, firstname, lastname, email_address).

Step #3: Test Data Redaction

Write the example of a page URL containing query parameters you want to delete and click on the button “Preview redacted data”. If it works as expected, save changes. GA4 will start to remove them within an hour.

Using GA4 Data Redaction to Exclude URL Query Parameters in GA4
Using GA4 Data Redact to Exclude URL Query Parameters in GA4

In order to remove old events containing the wrong data, use GA4 data deletion request feature.

Excluding URL Query parameters using Google Tag Manager

As mentioned at this article’s beginning, there is a second way to deal with unnecessary URL parameters. However, I would say it’s optional after GA4 released “Data redact” feature, but let’s explore how to do the same things using Google Tag Manager step by step. 

Time needed: 15 minutes

  1. Open Google Tag Manager and navigate to “Templates” page

    Open GTM and go to Templates tab

  2. Click on “Search Gallery” button under “Variable templates” section, select “Trim Query” template and add it to the workplace

    Find Trim Query in Variable Templates

  3. Go to “Variables” tab and create a new user-defined variable.

    1. Select “Trim Query” as a variable type
    2. Variable name “Page URL without Query Strings”
    3. Target URL : Page URL
    4. Write the parameters to remove (for instance, if your URL looks the following way your_domain/thank_you/?order_id=14124, you should provide “order_id” to remove this part “order_id=14124” ) 
    5. Save the variableCreate a new GTM varialbe using Trim Query template

  4. Go to your GA4 configuration tag and do the following adjustments:

    Provide a new field to set with the following settings:
    1. Field Name “page_location”
    2. Value {{Page URL without Query Strings}} (the variable you created in the step 3)
    3. Save changesModify GA4 Configuration Tag to Remove URL Query Parameters

  5. Publish the GTM container


After you do these five steps, GTM will send URLs without the specified queries. 

I recommend you use GTM Preview mode and GA4 DebugView to troubleshoot if everything works as expected. 

Note: since page_view events have two variables that refer to page URL: “page_location” and “page_referrer”, I recommend doing the same setup for the “page_referrer” variable as well.

Page Referrer without URL query parameters
Page Referrer without URL query parameters | GTM setup

Final Word

To summarize, excluding URL query parameters in Google Analytics 4 can help you avoid cardinality and send sensitive personal information. 

Although Google Analytics 4 doesn’t offer a filter to do it as Universal Analytics does, GA4 has a feature ‘Redact data” that can help you. Additionally, you can remove unnecessary UTM query parameters using Google Tag Manager.

If you have any questions, please don’t hesitate to comment below. 

Frequently Asked Questions

How to exclude URL Query parameters in GA4

To exclude URL query parameters use GA4 “Redact data” feature.

2 Replies to “How to Exclude URL Query Parameters in GA4”

Leave a comment

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