How to use a hostname filter in GA4

If you transited from Universal Analytics to Google Analytics 4, you are aware of all the filters Universal Analytics had, and you, most likely, want to replicate them in GA4. Although many blogs are written to teach you how to set up GA4 filters, including internal and developer traffic filters, there is not much information about a hostname filter in GA4. 

Therefore, l dedicated this blog post to keeping you updated about the latest GA4 news on a hostname filter. It means that I will update this article whenever a new GA4 update takes place

Let’s delve into it.

Is it possible to set up a hostname filter in GA4 the same way as in Universal Analytics?

The short answer is no. There is no possibility nowadays to set up a hostname filter using a GA4 interface. You can do it with Google Tag Manager. However, before doing something with that, you should check if there is a need. 

To see how many hostnames send the data into your GA4 account, please follow one of the following solutions:

Solution A:

  1. Login to the GA4 account
  2. Click on the Search bar and type “hostname”
  3. Select the report “Top Hostname by Users”
Showing-how-to-find-hostname-report-in-ga4-solution-a
Solution A: “Find Hostname vs Users” report

Solution B:

  1. Login to the GA4 account
  2. Go to Explorations and create a new one
  3. Import dimension “Hostname” and “Event count” metrics to the report
  4. Add the dimension and metrics to the report
Showing-how-to-find-hostname-report-in-ga4-solution-b
Solution B: “Find Hostname vs Users” report

You will see the number of users vs hostname report. If you see only one and it’s the right one, you likely don’t need to look after that. (similar to what I have on my screenshot) Just leave it for the time when Google release the hostname filter in GA4. 

Otherwise, if you have many hostnames and some of them are not relevant to your business, you can open a Google Tag Manager and set it up using the instructions provided in the next section of this article. 

Note: Please remember that filtering traffic in Google Tag Manager is not the same as filtering traffic in Google Analytics. If someone is sending data from their website with your GA4 measurement id, your GTM tag won’t be able to filter it. 

How to set up a hostname filter using Google Tag Manager for Google Analytics 4?

Time needed: 15 minutes

As I mentioned above, you need to use Google Tag Manager and take the following steps:

  1. Create a new variable

    1. Name “My Hostname RegEx Table”
    2. Variable Type – RegEx Table
    3. Input Variable – Page Hostname
    4. Pattern – your domain (for instance, www.vakulski-group.com)
    5. Output – your GA4-measurement Id (for instance, G-KF9LRYZ10K)How to set up Hostname GTM Variable

  2. Update your main GA4 tag to use the variable you created (after that, all your GA4 event tags will use that RegEx table)

    How to set up Hostname GTM Trigger

  3. Publish a GTM Container

    Publishing-gtm-container

If you have more than one domain to include, add more patterns in the RegEx table variable. 

How to apply a GA4 hostname filter in GA4 reports?

According to the note I wrote above, the Google Tag Manager setup has its own limitations. If you find yourself that you set up a GA4 hostname filter using GTM and GA4 still shows some hostnames that are not relevant, most likely, it’s something that you can’t control. 

Therefore, I can recommend only one solution to that – filter your GA4 data using a hostname dimension. It is suitable for all reports in Google Analytics 4 apart from the Real-Time Report. 

For instance, 

You can apply a filter in the GA4 Explorations report; just select dimension “Hostname” contains “your domain”. After that, you analyse the traffic of only the hostname you are interested in.

Showing how to apply Hostname Filter in GA4 Explorations Report
Showing how to apply Hostname Filter in GA4 Explorations Report

In all other reports, click on the audience, add a new condition, select “hostname” and select your hostname. After that, you can apply the filter.

Showing how to apply Hostname Filter in GA4 Acquisition Report
Showing how to apply Hostname Filter in GA4 Acquisition Report

Final Thought 

Unlikely Universal Analytics, Google Analytics 4 doesn’t have a native hostname filter. You can use Google Tag Manager to create a similar filter, but it has disadvantages. Otherwise, when analysing data, you can apply the hostname filter for GA4 reports. 

If you find this article helpful or know another way to filter GA4 data by hostname, please let me know by leaving a comment below. 



How do I add a hostname filter in Google Analytics 4?

At this moment, there is only one solution for that. You can use Google Tag Manager and set up a RegEx table variable to trigger the correct GA4 measurement id for the relevant hostname. 

Is there a GA4 hostname filter similar to what Universal Analytics had?

Unfortunately, there is no hostname filter in Google Analytics 4. Google can add it in the future, but for right now, there are only a few ways to address it using Google Tag Manager.  

5 Replies to “How to use a hostname filter in GA4”

  1. I was baffled to see the random spam bot traffic to non-existing pages, and this article clarified the situation : ) The instructions to set up a filter were helpful!

  2. Thank you for this. Now that Google is recommending using the same data stream for any sites on which you want cross-domain tracking, this ability to separate hostnames is critical!

  3. Or you can just edit the standard Pages and Screens report and set the primary dimension to Page Location.

Leave a comment

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