ShoryakuAI

GA4 hostname filters: blocking spam with an allowlist

Marketing10 min

A GA4 hostname filter (web hostname traffic filter) removes data from GA4 processing based on the domain that sent the event. Since September 21, 2026, besides listing domains to exclude one by one, you can use an "Include only" filter to allow only your own domains. What's new in Google Analytics

Anyone can read a GA4 measurement ID from your page's HTML, so data sometimes arrives from unrelated sites or from spam using your ID. With exclude filters, you had to add each new source as it appeared. With an allowlist, hostnames you did not register are never processed.

However, data filters are permanent, and excluded data cannot be recovered. This guide explains how to list the hostnames to register, how to test the filter, and what to check before activating it.

Filter types and how they work

GA4 data filters come in three types: developer traffic, internal traffic and web hostname traffic. Hostname filters behave as follows. Data filters help, Hostname filter setup

Item Detail
Filter operation Exclude, or Include only
Match type Exactly matches, Begins with, Ends with, Contains
State Testing, Active, Inactive
Order Active Include filters are combined and applied first as a group, then Exclude filters are applied in turn
Historical data Unchanged. Filters apply only to data received after creation
Excluded data No longer available in GA4 reports or BigQuery
Required role Editor or above at the property level

Google notes two points about Include filters:

  • They are not applied to events sent from the Measurement Protocol. Purchases or other events you send from a server are not blocked
  • They automatically block events with empty hostnames, since a missing hostname typically indicates spam or abnormal traffic

Exclude list or allowlist?

Point Exclude (blocklist) Include only (allowlist)
What you enter Unwanted source domains Domains you want to measure
New spam Add each new source No extra work
Typical failure Missed entries leave spam in A missed own domain loses valid data
Best when You only want to stop specific sources Your measured domains are fixed and can be listed

If your site has a small, fixed set of domains, an allowlist takes less work. On the other hand, forgetting one domain permanently loses that domain's data. That is why the inventory and testing below matter.

List the hostnames to register

Start by listing the hostnames currently sending data to GA4.

  1. List them in Explore. In a free-form exploration, add "Hostname" as a dimension and "Event count" as a metric, and look at the last few months.
  2. Mark your own. Check the production domain, with and without www, and subdomains such as blog, help or member pages.
  3. Add pages on other domains. If you measure booking, payment or form pages on another domain with cross-domain measurement, that domain is also in scope. See GA4 cross-domain setup.
  4. Decide what to keep. Leave out development or staging hostnames if you do not want them in production reports.

Keeping the inventory in a table like the one below lets a successor understand the decisions. These rows are examples.

Hostname Purpose Include Checked by / how
example.com Production site Yes Confirmed with web developer
www.example.com Production site (with www) Yes Confirmed in Explore
reserve.example.net Booking page (other domain) Yes Cross-domain measurement set up
staging.example.com Staging environment No Keep out of production numbers
Unknown domain Unknown No Not managed by you

Do not assume an unfamiliar hostname is spam right away; check with your web developer or external tool owners. Translation services or page builders sometimes run your measurement on another domain.

From testing to activation

Google's steps are create, verify and activate. Hostname filter setup

  1. Create the filter. Go to Admin → Data collection and modification → Data filters → Create filter → Web hostname traffic filter. Choose "Include only" as the filter operation, enter the match type and hostname, and create it in the Testing state.
  2. Wait 24 to 36 hours and verify. In a free-form exploration, add "Test data filter name" and "Event name" as dimensions and "Event count" as a metric, and filter on "Test data filter name" containing your filter's name. Confirm that only the intended hostnames appear.
  3. Activate it. After verification, set the filter state to Active and save. Filtering starts within 24 to 36 hours.

Use "Ends with" for a whole domain or "Exactly matches" for a specific hostname to reduce unintended matches. For example, "Contains" with example also matches a different domain such as example-spam.com.

Pre-activation checklist

□ Listed the last few months of hostnames and noted the purpose of each of yours
□ Registered www and non-www, subdomains, and cross-domain booking or payment pages
□ Used "Exactly matches" or "Ends with" rather than "Contains"
□ Left the filter in Testing for 24 to 36 hours and checked the results by test data filter name
□ Recorded the activation date in your internal work log
□ Checked other exclude filters (such as internal traffic) and the order in which filters apply

Internal traffic exclusion is covered in excluding internal traffic in GA4.

After activation

A drop in sessions or events around the activation date may simply mean spam was removed. Check that the drop matches the volume of the sources you marked "No" during the inventory.

If the drop is much larger than expected, you may have missed a hostname. Data filters cannot restore past data, so switch the filter back to Testing or Inactive as soon as you notice, and review the list. Exclude the affected period when comparing ad or SEO results.

When you analyze GA4 data in Shoryaku AI, tell the chat the date you activated the filter so a drop in sessions is not misread as worse acquisition. Spam left in the data can lead an AI to suggest improvements for traffic sources that do not really exist, so cleaning the data first is worth it.

Start with the hostname list

Today, list hostnames in a GA4 exploration and separate yours from the rest. If you find unfamiliar sources, decide whether to build an allowlist or block them individually with exclude filters. Either way, verify in the Testing state before activating.