Categories
Website Tracking

How To Remove Query Strings From Page Path URL in GA4

If you upgraded your Google Analytics to GA4 there’s a big chance that you are seeing some query strings in your reporting.

Within the GA4 reporting, there is only an option to show your URLs as “Page path + query string and screen class”. Within Universal Analytics, you might have excluded some query strings and parameters from the URL (for example Facebook’s FBCLID parameter).

Removing parameters from GA4

GA4 does not give an option to filter out query strings on the account level.

Luckily, you will be able to do this via Google Tag Manager.

Step 1: Add a custom javascript to GTM

As a first step, you will need to add a custom javascript to your Google Tag Manager.

Go to “Variables” and create a new “User-Defined Variable”. Select “Custom JavaScript” as a Page Variable and copy the following code.

function(){
  return document.location.hostname + document.location.pathname;
}

See below what this will look like.

GA4 - Remove Querystrings From Page Path step 1

Step 2: Update your GA4 tag

Then, jump into your GA4 tag. Go to “Tags” and select the appropriate tag.

Within “Fields to set” add a row with the Field Name “page_location”. As the value, select the Javascript you just created.

GA4 - Remove Querystrings From Page Path step 2

Step 3: Publish your changes

Don’t forget to publish your GTM changes. This will remove any query strings and parameters from your reporting going forward (it won’t change any of your previous data!).

Share this:

By Jeroen

With over years of experience in digital marketing, Jeroen helps businesses to get more results out of their online advertising budgets.

Leave a Reply

Your email address will not be published.