Google Analytics 4 (GA4) helps businesses understand where website visitors come from, which pages they visit, how they interact with content and whether they complete important actions. However, the accuracy of these insights depends on the quality of the data being collected.
One issue that can affect analytics reporting is unexpected hostname traffic.
You may occasionally find website events associated with domains that do not belong to your business. These could include staging environments, test domains, improperly configured websites or unrelated domains where your GA4 Measurement ID is being used.
When these events enter your GA4 property, they can complicate traffic analysis, create confusion around landing-page performance and make it harder to evaluate marketing results.
GA4 provides a dedicated Web hostname traffic filter that allows you to specify which hostnames should be processed or excluded. Its Include only option is particularly useful when you want to restrict incoming web hostname data to approved domains.
In this guide, we explain how hostname pollution occurs, how to investigate unexpected hostnames, how to configure an Include only filter, and how to validate the setup before applying it to your production analytics data.
What Is a Hostname in Google Analytics 4?
A hostname is the domain or subdomain through which a visitor accesses a website.
For example, consider the following URLs:
| Website URL | Hostname |
|---|---|
| https://www.example.com/services/ | www.example.com |
| https://example.com/contact/ | example.com |
| https://blog.example.com/seo-guide/ | blog.example.com |
| https://staging.example.com/home/ | staging.example.com |
GA4 automatically collects the Hostname dimension for web page activity.
You can use this dimension to understand which domains are sending events to your GA4 property.
For a business operating only on www.example.com, unexpected hostname values such as test.example.net or unrelated domains may indicate a tracking configuration issue that deserves investigation.
However, an unfamiliar hostname is not automatically spam. It could represent a legitimate subdomain, a development environment, a third-party implementation or another website using the same measurement configuration.
The first step should always be to investigate the hostname rather than immediately filtering it.
What Is a GA4 Hostname Include Filter?
A GA4 Web hostname traffic filter is a data filter that controls which hostname-related traffic is processed by your Analytics property.
GA4 provides two main filter operations:
Exclude: Excludes data matching the hostname conditions you specify.
Include only: Processes only data matching the hostname conditions you specify.
For example, suppose your business website uses example.com and www.example.com.
You may want your GA4 property to process traffic from these approved hostnames while excluding unexpected domains.
An Include only filter helps achieve this by restricting incoming data to the hostnames you have specified.
Unlike a report-level filter, an active data filter affects the processing of incoming data. This distinction is important because excluded events are not simply hidden from a report; they are permanently excluded from the processed Analytics data.
Google provides the official configuration instructions in its guide to filtering web hostname traffic in Google Analytics.
Why Can Unwanted Hostnames Appear in GA4?
Before configuring a hostname filter, it is useful to understand why unexpected hostname values may appear in your reports.
There are several possible causes.
1. Your GA4 Measurement ID Is Used on Another Domain
A GA4 Measurement ID identifies the web data stream receiving website events.
If the same Measurement ID or tracking configuration is unintentionally installed on another website, that website may send events to your GA4 property.
For example, your business website may use:
www.example.com
But you may also find events associated with:
anotherwebsite.com
This could happen if someone copied your tracking code, reused a tag configuration or incorrectly implemented the same Measurement ID.
The unexpected hostname should be investigated to determine whether the tracking implementation is authorised.
2. Staging and Development Environments Send Data to Production GA4
Websites commonly have separate environments for development, testing and production.
For example:
www.example.com – Live website
staging.example.com – Staging environment
dev.example.com – Development environment
If all these environments use the same GA4 Measurement ID, their activity may appear in the same property.
This can create confusion when reviewing website sessions, page views and engagement metrics.
A hostname filter can help restrict the processed data to approved production hostnames, provided you have identified all environments that should legitimately be included.
3. Tracking Configuration Is Reused Incorrectly
Another possible cause is an incorrectly implemented Google tag or Google Tag Manager configuration.
For example, a developer may duplicate an existing website configuration when launching a new domain without updating its measurement settings.
As a result, events from the new website may enter the original GA4 property.
Review your Google Tag Manager containers, Google tag installations and website source code if you discover unexpected hostnames.
4. Automated or Unwanted Events Reach Your Property
Unwanted analytics events can sometimes appear alongside genuine website activity.
However, hostname filtering and bot filtering solve different problems.
A hostname filter checks the hostname associated with incoming web events. It does not identify every bot, fraudulent interaction or automated request.
If suspicious activity is coming through your legitimate hostname, investigate the event patterns, traffic sources and technical implementation separately.
How to Identify Unexpected Hostnames in GA4
Before creating an Include only filter, identify which hostnames currently send data to your GA4 property.
This is one of the most important steps because an incorrect filter can exclude legitimate website activity.
Step 1: Open Your GA4 Property
Log in to Google Analytics and select the property you want to investigate.
Make sure you select the correct property, particularly if your organisation manages multiple websites or GA4 properties.
Step 2: Open the Pages and Screens Report
Navigate to:
Reports → Engagement → Pages and screens
The report provides information about the pages users interact with on your website.
You can use the Hostname dimension to understand which domains are associated with the reported activity.
If the Hostname dimension is not visible in your report, you may need to customise the report or use an Exploration.
Step 3: Use the Hostname Dimension in Explore
For a more detailed investigation:
Open Explore.
Create a new Free form exploration.
Add the Hostname dimension.
Add Event name as another dimension.
Add Event count as a metric.
Place Hostname in the Rows section.
Place Event count in the Values section.
You can also add additional dimensions, such as Page path and screen class, where useful and compatible with your exploration.
This allows you to review which hostnames are associated with incoming events and understand what activity is being recorded.
Step 4: Classify the Hostnames
Do not assume every hostname other than your primary domain is spam.
Create a simple classification before applying any filter.
For example:
| Hostname | Classification | Recommended action |
|---|---|---|
| www.example.com | Approved production domain | Include |
| example.com | Approved alternative domain | Include if it legitimately receives traffic |
| blog.example.com | Business subdomain | Investigate and include if required |
| staging.example.com | Development environment | Exclude if production reporting should not contain it |
| unknown-example.net | Unexpected domain | Investigate before excluding |
| unrelated-domain.com | Unauthorised hostname | Exclude if confirmed |
Note: This is an illustrative hostname audit, not actual Surch or client analytics data.
Document the approved hostnames before creating the filter.
This makes it easier to validate the configuration and reduces the risk of excluding genuine traffic.
How to Set Up a GA4 Hostname Include Filter
Once you have identified your approved hostnames, you can configure the filter within GA4.
You need Editor or higher permissions at the property level to create and manage data filters.
Step 1: Open Data Filters
Sign in to Google Analytics.
Select the correct GA4 property.
Click Admin.
Under Data collection and modification, select Data filters.
Click Create filter.
Choose Web hostname traffic filter.
You should now see the hostname filter configuration.
Step 2: Enter a Filter Name
Choose a descriptive name that explains the purpose of the filter.
For example:
Production Hostname Allowlist
A clear naming convention helps other team members understand the filter when reviewing the GA4 configuration later.
Avoid generic names such as "Filter 1" or "Website Filter".
Step 3: Select the Include Only Operation
Under Filter operation, choose:
Include only
This tells GA4 to process only events matching the hostname conditions you specify.
You will also need to configure the hostname and match type.
Google provides the following match types:
| Match type | How it works |
|---|---|
| Exactly matches | Matches the hostname only when the value is identical |
| Begins with | Matches hostnames starting with the specified value |
| Ends with | Matches hostnames ending with the specified value |
| Contains | Matches hostnames containing the specified value anywhere |
For most production hostname allowlists, exact matching is the safest starting point because it reduces the possibility of unintentionally matching unrelated domains.
Step 4: Configure the Approved Hostname
Suppose your website uses:
www.example.com
You can configure the filter using:
Filter operation: Include only
Match type: Exactly matches
Hostname: www.example.com
This allows the specified hostname to match.
What if your website uses both www and non-www hostnames?
For example:
example.com
www.example.com
Do not assume that entering example.com with a Contains condition is an exact allowlist.
A Contains condition may also match a hostname such as:
example.com.fake-domain.net
Instead, you can create separate Include only filters using exact hostname matches for each approved hostname.
For example:
| Filter | Operation | Match type | Hostname |
|---|---|---|---|
| Production hostname – www | Include only | Exactly matches | www.example.com |
| Production hostname – root | Include only | Exactly matches | example.com |
Google documents that active Include only data filters are combined as a group. This means multiple approved hostname filters can work together as an allowlist.
Only create filters for hostnames that genuinely need to send data to the property.
Step 5: Set the Filter State to Testing
Do not activate the filter immediately.
First, select:
Filter state → Testing
Testing mode allows GA4 to identify events that match the filter conditions without permanently excluding them from processed reporting data.
This is particularly important for Include only filters because an incorrectly configured allowlist can exclude legitimate traffic.
Review the filter name, operation, match type and hostname before creating it.
Click Create when the configuration is ready.
How to Test and Validate the GA4 Hostname Filter
Testing is not just a recommended precaution. It is an important part of the implementation process.
Google provides a specific validation workflow using the Test data filter name dimension.
Step 1: Allow Time for Testing Data
After creating the filter in Testing mode, wait approximately 24–36 hours before validating it.
This gives GA4 time to process and make the relevant test data available.
Step 2: Open Explore
Navigate to:
Explore → Free form
Create a new exploration for validating the hostname filter.
Step 3: Add the Required Dimensions and Metrics
Add these dimensions:
Test data filter name
Event name
Hostname
Add this metric:
Event count
Step 4: Configure the Exploration
Set up the exploration as follows:
| Exploration section | Configuration |
|---|---|
| Technique | Free form |
| Rows | Test data filter name, Event name |
| Values | Event count |
| Filter | Test data filter name contains your filter name |
Use the exact filter name you created earlier.
Google's validation instructions specify using the Test data filter name and Event name dimensions, with Event count as the metric.
Review the resulting hostname data to confirm that the filter is affecting the intended traffic.
Step 5: Investigate Unexpected Results
Before activating the filter, check the following:
Are all approved production hostnames represented?
Are legitimate subdomains being handled correctly?
Are unexpected hostnames still appearing in the test results?
Is the match type too broad?
Does the filter configuration reflect your actual tracking setup?
If you find an unexpected result, review the hostname conditions and correct the configuration before activation.
Do not activate the filter simply because the testing exploration contains some matching events.
The purpose of validation is to confirm that the allowlist matches your actual website environment.
How to Activate the Hostname Include Filter
Once you have validated the filter and confirmed that the approved hostname conditions are correct, you can activate it.
Follow these steps:
Open Admin in GA4.
Navigate to Data filters.
Select your hostname filter.
Locate Filter state.
Change the state from Testing to Active.
Review the configuration.
Save the changes.
After activation, GA4 applies the filter to incoming data.
Google notes that an active hostname filter can take approximately 24–36 hours to begin filtering data.
Continue monitoring the hostname dimension and important reporting metrics after activation.
Important Risks and Limitations of GA4 Hostname Filtering
Although hostname filtering is useful for analytics data hygiene, it is important to understand what it can and cannot do.
1. Active Filters Permanently Affect Incoming Data
GA4 data filters are not reversible in the sense of restoring excluded events.
When an active filter excludes incoming data, those events are not processed and are not available in GA4 or BigQuery.
This means you should validate your configuration carefully before activating it.
2. Filters Do Not Change Historical Data
Hostname filters apply to incoming data from the point of creation forward.
They do not remove unwanted hostname activity from previously collected reports.
If historical reporting contains unexpected hostnames, you will need to investigate those reports separately and use appropriate reporting filters or analysis methods.
3. A Hostname Filter Does Not Block Visitors
A GA4 hostname filter is an analytics data-processing control.
It does not:
Block visitors from accessing your website.
Prevent requests from reaching your server.
Stop malicious bots from crawling website pages.
Block attacks against your hosting infrastructure.
Replace a web application firewall.
If you need to block malicious requests, investigate appropriate security controls such as server-level rules, hosting security features or a web application firewall.
4. Legitimate Subdomains Must Be Considered
Some businesses operate multiple website environments under different subdomains.
For example:
blog.example.com
shop.example.com
app.example.com
If these environments legitimately send data to the same GA4 property, excluding them without investigation may result in incomplete analytics reporting.
Review the business purpose of each hostname before applying the allowlist.
5. Hostname Filtering Is Not Complete Bot Protection
Unexpected hostname data and bot traffic are not necessarily the same problem.
A bot can visit your legitimate production hostname, while an unexpected hostname can be associated with a genuine testing environment.
A hostname filter only addresses the hostname conditions configured within the data filter.
It should be combined with other analytics and website security checks where necessary.
Common Mistakes to Avoid
Even when the hostname filter is correctly available in GA4, implementation mistakes can affect reporting quality.
Using Contains Instead of Exact Matching
A broad Contains condition can match unrelated hostnames that include the same text.
Where possible, use exact matching for individual approved hostnames.
Forgetting the Non-WWW or WWW Version
If both versions legitimately send events to your property, make sure both are included in the allowlist.
Do not assume one hostname automatically covers the other.
Activating the Filter Without Testing
Include only filters can exclude legitimate events if the hostname conditions are incomplete.
Always use Testing mode and validate the results in Explore.
Ignoring Staging and Development Environments
Development environments may send events to the production property if they share the same Measurement ID.
Review your tracking implementation and decide whether these environments should be included.
Expecting Historical Data to Be Cleaned Automatically
Data filters do not retroactively modify previously collected analytics data.
Do not expect existing reports to change after activating the filter.
Treating Hostname Filtering as a Security Solution
The filter does not block traffic at the server level.
Use appropriate website security measures if the issue involves malicious requests rather than unwanted analytics events.
GA4 Hostname Filter Implementation Checklist
Before activating the filter, use this checklist to review the implementation.
Confirm that the correct GA4 property is selected.
Review the Hostname dimension in GA4.
Identify all approved production hostnames.
Investigate unfamiliar hostnames.
Check whether staging or development environments share the Measurement ID.
Create the Web hostname traffic filter.
Select Include only.
Use appropriate hostname match types.
Create separate exact-match filters where multiple hostnames are required.
Save the filter in Testing mode.
Wait approximately 24–36 hours.
Validate the results using Explore.
Activate only after confirming the configuration.
Monitor reporting after activation.
This process helps reduce configuration errors and provides a more controlled approach to maintaining GA4 data quality.
Frequently Asked Questions
What is a hostname filter in GA4?
A hostname filter is a GA4 data filter that controls which website hostnames are processed by your Analytics property. It can be configured to include only approved hostnames or exclude specific hostname values.
How do I exclude spam hostnames in GA4?
First, identify unexpected hostnames using the Hostname dimension in GA4. Then create a Web hostname traffic filter under Admin → Data filters. Select Exclude if you want to remove specific hostnames, or Include only if you want to process only approved hostnames.
Can I include both www and non-www domains in GA4?
Yes. You can create separate Include only filters using the Exactly matches condition for each approved hostname. Active Include only data filters are combined as a group.
Does a GA4 hostname filter remove historical spam data?
No. GA4 data filters apply to incoming data and do not change previously collected reports. Historical hostname data must be investigated separately.
How long does it take for a GA4 hostname filter to work?
Google recommends waiting 24–36 hours before validating a filter in Testing mode. After activation, the filter can also take approximately 24–36 hours to begin filtering incoming data.
Does hostname filtering stop bots from visiting my website?
No. Hostname filtering controls analytics data processing. It does not block website requests, prevent bots from crawling pages or replace server-side security controls.
Is an Include only hostname filter better than an Exclude filter?
It depends on the requirement. Include only is useful when you have a clearly defined list of approved hostnames and want to restrict processed data to those domains. Exclude is more appropriate when you want to remove a specific known hostname while retaining other traffic.
Conclusion
Unexpected hostname activity can make GA4 reports harder to interpret and complicate SEO and marketing performance analysis.
The GA4 Web hostname traffic filter provides a practical way to control which hostnames are processed by your Analytics property. By using the Include only operation, businesses can restrict incoming web hostname data to approved domains.
However, successful implementation requires more than simply entering a domain name into a filter.
Start by auditing existing hostname data, identifying legitimate website environments and selecting appropriate matching conditions. Use exact matching where possible, validate the filter in Testing mode and activate it only after confirming the results.
Most importantly, remember that hostname filtering is one part of a wider analytics data-quality process. Regular tracking audits, correct tag implementation and appropriate website security controls are still necessary to maintain reliable reporting.

