Query parameters in reports: why remove them and how?

Unlike the previous version, the new Google Analytics 4 has no built-in feature for excluding URL query parameters from reports.

Martin Jelínek

Martin Jelínek

Certified PPC Specialist & Data Analyst

16. July 2024

4 min

Advanced

Unlike the previous version, the new Google Analytics 4 has no built-in feature for excluding URL query parameters from reports. For this you therefore have to use Google Tag Manager, which allows URL filtering. Read on for what query parameters actually are, what they are for and how you can remove them from your Google Analytics account. 

Contents

What are query parameters?

Query parameters are parts of a URL with additional information for the web server. Thanks to them it can carry out a specific action. They are placed after a question mark (?). Each parameter is separated by an ampersand (&) and consists of a name and a value separated by an equals sign (=).

Query parameters (marked in red) may look like this, for instance:

https://www.invelity.com/hladat?utm_source=priklad45&utm_medium=cpc&productid=16485

Why remove query parameters from GA4?

Google Analytics 4, like its predecessor, considers the same page two different web pages if they contain different query parameters. 

Let us show it with a specific example: these 2 URLs show the same sub-page. GA4, though, treats them as 2 different pages in its reports.

/en/services?utm_source=priklad&product=test&kwgid=12633

/en/services?utm_source=priklad&product=test&kwgid=45454

What is the problem? Imagine you own an e-shop with thousands of products that can be filtered by colour, size or other parameters. Every combination of these parameters appears in the URL as a query. It will then be far harder for you to record one page's or product's performance. Even with a single product, query parameters will fragment your data. 

Identifying query parameters

Step 1: open GA4

First sign in to your Google Analytics account and choose the property you want to show query parameters for.

Step 2: go to "Explore"

In the left panel click the "Explore" option. This section lets you create your own reports and explore data as you need.

exploring reports when identifying query parameters

Step 3: create a new exploration

Click the "+ New exploration" button and create a new custom report.

creating a new exploration when identifying query parameters

Step 4: add dimensions and metrics

In the exploration you need to add the dimensions and metrics you are interested in. In the panel on the left click "Add dimensions" and "Add metrics".

  1. Dimensions: look up the dimension "Page path + query string" 
  2. Metrics: add metrics such as Views, Sessions or other relevant metrics.
adding dimensions and metrics when identifying query parameters

Step 5: apply a filter for query parameters

Click "Add filter" and choose "Page path + query string" with the condition contains "?".

As we already mentioned, query parameters come after a question mark. Thanks to this filter you will see them all. 

applying a filter to identify query parameters

An illustration of what your report will look like:

an example of a query parameter report

In it you can see all the unnecessary parameters.

How to remove query parameters?

Step 1: signing in and choosing a template

Sign in to your Google Tag Manager account. Click "Templates" and then "Search Gallery" under the "Variable Templates" section.

signing in and choosing a template for removing query parameters

Then find the template named "Query Parameter Stripping Utility" from the creators at the analytics firm Cardinal Path.

Click "Add to workspace" and "Add".

Google Tag Manager – Query Parameter Stripping Utility template with the Add to workspace button

Step 2: creating a variable that will exclude query parameters

In the left panel go to the "Variables" section and then click "New" in the "User-Defined Variables" section.

creating a variable for removing query parameters

Name the variable so that you know what it stands for. At Invelity we use the name "Trim Query". Then click "Variable configuration." The right panel with various variables will open.

Google Tag Manager – naming the Trim Query variable and opening its configuration

Among the variables choose the one named "Query Parameter Stripping Utility".

Google Tag Manager – selecting the Query Parameter Stripping Utility variable type

Now your variable's configuration will appear. Here you leave the "Exclude All Parameters" box ticked, unless you plan to exclude only some selected ones. If you do, choose the second option "Exclude Certain Parameters". In the first field you can keep parameters if you wish; if not, leave the field empty.

In the bottom field "Field which needs parameters removed" enter the variable named {{Page URL}} and click "Save" in the top right.

Google Tag Manager – Trim Query variable configuration with the {{Page URL}} field and Save button

In the left panel click "Tags" and find your Google tag, or the older "Google Analytics: GA4 Configuration" tag. Click it and then "Tag Configuration".

Google Tag Manager – opening the Google tag configuration for GA4

Now the tag's settings will open. Go to "Configuration settings". After clicking "Add row" 2 new fields will appear that you have to fill in.

tag configuration

In the first field under "Configuration parameter" add the value page_location and in the second under "Value" add {{Trim Query}}

Finally do not forget to save the tag with the button in the top right.

Google Tag Manager – page_location parameter set to {{Trim Query}} in the GA4 tag settings

Testing

Do you want to test whether parameter removal is set up correctly? Click "Preview" in the top right.

Google Tag Manager – Preview button highlighted to start debug mode

Then enter your website's URL. Add the query parameters from the report to it, or enter test ones. 

Do not forget that query parameters come after "?" and are separated by "&".

Now you only have to click "Connect".

Tag Assistant – connecting to the site with a test URL containing query parameters

Tag Assistant will automatically open a new window with your site. You therefore have to click back to the window with Tag Assistant. 

In the left menu you will find the events where tags fire. You will most likely find your Google tag under "Container Loaded", or under "Consent Update" (the name may differ slightly depending on the cookie bar). 

After clicking the Google tag, a window will open with the information the tag sends. In the top right next to "Display Variables as" tick "Values". This way you can check whether the "page_location" parameter contains any excluded query parameters.

Tag Assistant – Google tag details showing page_location without query parameters

You can also check the removal of query parameters through GA4. Take a look at how to grant access to Google Analytics. 

After clicking "Admin" in the left menu, click through to "DebugView". Once your Google tag fires, events will appear. Click the event named "page_view" and find your "page_location" parameter again, where you will see the URL without queries.

testing query parameters

If everything works as it should, do not forget to click "Submit" in Tag Manager in the top right and publish your changes. If you cannot make sense of it, do not hesitate to get in touch. We will be glad to help.

I am interested in a tailor-made website

Get in touch and arrange a meeting with us in Bratislava, Zvolen or even San Francisco. We will be glad to help you with your project.

Contact form

Recommended reading

The latest trends, proven practices and analyses from the digital world. Find out how to take your technology and marketing growth further.