Skip to content
Tips & tricks

How to block test and spam sites in GA4

What if part of the traffic in your reports did not belong to your site at all? Whether it is a forgotten test environment, a cloned site or a spammer copying your Google Tag Manager ID, parasite events can skew your Google Analytics data. Find out how to identify these unauthorized domains and permanently lock down your property with the allowlist method.

Alexis Neve 2 min read

Why unknown domains send data to your GA4

There are 3 main scenarios where external domains send traffic to your account:

  1. Staging environments: a developer duplicates your site for a redesign or for tests. If they do not isolate the tracking code, every test action is counted in your reports.
  2. Scraping and site clones: a third-party site steals or automatically translates your HTML code without removing your GA4 code.
  3. GTM spam: a spammer directly copies your Google Tag Manager script (GTM-XXXXXX). Every time a visitor loads their site, it sends its data to your reports.

Result: your overall metrics are completely polluted (inflated number of sessions, engagement rate and conversion rate in free fall).

The principle: control the hostname

Every event sent to GA4 automatically carries the Hostname dimension, meaning the real domain where the action took place (for example www.example.com).

Previously, the only solution was to manually exclude each parasite domain (Exclude). The problem? It was an endless chase against new spammers.

Now, GA4 lets you reverse the logic with an allowlist (Include filter): you list only your official domains and everything else is automatically rejected.

Tutorial: Audit your hostnames in GA4

Before blocking anything, take stock of the domains that send you traffic.

1. Create the report

Go to Explore > Free form.

2. Set up the data

In the left column, add:

  • Dimension: Hostname
  • Metric: Sessions

Drag Hostname into rows and your metric into values. Analyze a recent period and sort by descending volume.

3. Sort your domains

  • Your official domains: legitimate traffic
  • Technical environments (localhost, staging.exemple.be): manage your sites and containers to send this traffic to a new property
  • Spam domains and cloned sites: to block

How to permanently block parasite traffic (Allowlist)

Instead of keeping an endless blocklist, create an inclusion filter (Include) to keep only your validated domains.

  1. In GA4, go to Admin > Data collection and modification > Data filters.
  2. Click Create filter and select Web hostname traffic.
  3. Name your filter (for example: Allowlist - Official domains).
  4. In the filter type, switch from Exclude to Include only.
  5. Enter your legitimate domains.
  6. Keep the filter in the Testing state for 24 to 48 hours.

In the Testing state, GA4 tags the events to be removed with the Test data filter name dimension. Check in an exploration that your domain and subdomains do not appear there, then switch the filter to the Active state. An active filter is permanent. Also, the filter does not apply to data already collected. To remove it from your analyses, filter the exploration on your hostname.

Tools

  • Google Analytics 4: explorations with the Hostname dimension, data filters.

Data quality auditing is part of the Google Analytics consultant expertise, together with the tracking audit and reporting.

Ready to take action?

Tell me about your site and your Ads platforms: you get a clear answer within 48 hours.

Get a quote