Google Analytics : part: 32

Google Analytics : part: 32

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?

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

Free e-book:

Getting Started with

Google Analytics 4

Learn how to properly install GA4, track events, conversions, build reports



SUBSCRIBE TO NEWSLETTER. GET THE E-BOOK.

Unsubscribe at any time.

?

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

?

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.

要查看或添加评论,请登录

Soyeb Islam T.的更多文章

  • Google Tag Manager : part : 20

    Google Tag Manager : part : 20

    How to Move Google Tag Manager Container to Another Account There might be some situations where you want to move the…

  • Google tag manager: part: 19

    Google tag manager: part: 19

    Google Tag Manager Container Code. In or ? Google Tag Manager official recommendation states that in order to install…

  • Google Tag Manager : part 18

    Google Tag Manager : part 18

    Benefits of Server Side Tagging (with Google Tag Manager) You have probably heard multiple people talking about how…

  • Google Analytics : Part : 38

    Google Analytics : Part : 38

    Google Analytics Client ID vs User ID If you have ever tried to track additional data about your…

  • Google Analytics: part: 37

    Google Analytics: part: 37

    Sudden drop in bounce rate of Google Analytics? Here is how to fix it One day you open your Universal Analytics (GA3)…

  • Google Tag Manager : part : 16

    Google Tag Manager : part : 16

    GTAG vs Google Tag Manager. What is the Difference? What to Choose? GTAG and Google Tag Manager are completely…

  • Google Tag Manager & Analytics : part 15

    Google Tag Manager & Analytics : part 15

    GTAG vs Analytics.js When you want to install Google Analytics on your website, one of the options is to add its code…

    1 条评论
  • Google Tag manager : part : 14

    Google Tag manager : part : 14

    Google Tag Manager Firing Twice? Here’s a solution Here’s a situation. You are using a Google Tag Assistant (legacy)…

  • Google Analytics : part : 36

    Google Analytics : part : 36

    Introducing Google Analytics 4 Community 4 years ago, I launched a Google Tag Manager community on Facebook and now it…

  • Google Analytics : part : 36

    Google Analytics : part : 36

    16 Ways to Reduce Direct Traffic in Google Analytics Direct traffic in Google Analytics is often misunderstood. If you…

社区洞察

其他会员也浏览了