How to block Ghost spam?

Keep it simple, stupid.

There are basically two types of spam : ghost spam and spam referrer. Spam referrer visits your website and can be filtred with our custom segment. While Ghost spam can’t be filtred because it doesn’t come on your website to pollute your reports. Ghost spam uses the Analytics Measurement Protocol to attack your reports directly without passing through your Site. This Protocol is intended to allow developers to send data directly to Google Analytics Servers, but spammers found a way to use it for their benefit. Hopefully, there is one simple solution to block ghost spam that we will try to teach you.

1/ First, open up your Analytics account and go to Audience > Technology > Network then click on Hostname.
If you are clean, you will see only few hostnames:

Note all the valid hostnames of the list (your domain,,, etc.). For us, we used these:


2/ Click on the Admin tab, then on Filters to create a new one. We won’t include this filter because it must be customized with your own valid hostnames. Create a new filter that will INCLUDE Hostnames only from the list you defined earlier. Make a filter regex pattern. For us, it is now :||

Historic data will not be affected, but you can use the above rules on the advanced segment, which would allow you to analyze clean historic data.

In addition to that, go to admin/view settings and turn on the “Exclude all hits from known bots and spiders” option.

One more thing. There is another type of spam, which is mostly not considered as such. I am talking about traffic from irrelevant countries.

If you sell (target) globally, that’s great. But if you are selling locally, or only in several countries, then all other traffic is distorting your numbers and conversion rates.

It is nice to have that traffic, and it shouldn’t be filtered out, of course, but what should be done is creating a segment which includes only the traffic from relevant countries. Only then you can focus on correct numbers.

What gets measured, gets managed.