Find and Block Referral Bot Spam in Google Analytics

We take a look at how to find and stop bot traffic in Google Analytics.

We recently noticed a fairly decent uptick in traffic on the Echidna website, and at first we took pride, thinking that efforts to promote our site were paying off. Unfortunately, though, we got a little too excited, because in reality it was simply bot/spam traffic. The spike there at the end shows the increase in traffic due to spam referrals.

Google Analytics Bot Spam Traffic Increase

How to spot fake traffic

Spotting fake traffic in your analytics data should be fairly simple. At the most basic level, if your site experiences a spike in traffic that you weren’t expecting, something might be up. Even if you don’t notice anything out of the ordinary, though, you can easily go into your Google Analytics and make sure all of your traffic is legitimate. Just navigate to Acquisition > All Traffic > Channels, and you’ll see a list of your traffic sources.

Fake bot traffic in Google Analytics

As you can see in ours, the top three were illegitimate. How could we tell? Well, first, we didn’t recognize the sources as sites that have we have inbound links coming from. Second, one really easy way to double check is to simply Google the domain names. If it’s spam, the first page of results should make that pretty obvious. Take the Darodar search for example.

Darodar spam bot referral traffic Google Analytics

How to fix it, the quick and easy way

It’s nice to be able to identify spam/bot referral traffic, but if you’re like us, you probably want to do something about it. There are a lot of possible ways to fix it, but one simple way is just to create a new view filtered by hostname — this will basically only let in good traffic, instead of trying to manually block all bad traffic. If you need more details on why this works (or if you want a very thorough guide on spam affecting your analytics), check out this article.

1. Identify legitimate hostnames

You need to take a look at all of the hostnames by navigating to Audience > Technology > Network and then clicking on Primary Dimension: Hostname (check out the screenshot below if you’re having trouble finding it).

Google Analytics Hostname

The legitimate hostnames should include your own and any other sites that your Google Analytics tracking ID is linked to (e.g., YouTube, other analytics tools, shopping cart systems, etc.). Some common spam hostnames that we found included,, and All that matters at this step is identifying the legitimate hostnames so that you can include them in the next step.

2. Create your filter expression

Once you’ve gathered all of the hostnames you need to include, list them out with each full URL being separated by a vertical bar, as shown below:|||
Next, simple add a backslash (note: backslash, not forward slash) in front of each period in the expression:

3. Implement your new filter

Before you actually do this, just know that you need to be careful here, or you might end up excluding valid traffic. If you have multiple views set up already, it would probably be a good idea to test out this filter on only one view and then compare views to ensure you’re not blocking any genuine traffic. If you only have one view set up, you should probably set up a new view to test out before implementing the filter on your primary view.

Once you’re in your chosen view, go to Admin > View > Filters and create a new filter. Enter your Filter Name, use a Custom Filter Type, and select the Include option. From there, select Hostname under Filter Field, and then simply enter your above expression under Filter Pattern. Verify that it works, and then save the filter. That’s it, you’re done!

4. Wait for analytics data to accumulate

This won’t retroactively remove spam data, but it will prevent spam data from being included in future reporting. To make sure it’s working properly, simply wait for some data to accumulate, and then compare this new view with an old one. Doing so will ensure that spam traffic is being blocked and all legitimate traffic is being let through.

If you want to exclude spam referral data from historical reports, you’ll need to create a segment to do so. Just go to Reporting and then click + Add Segment, as shown in the screenshot below.

Add Segment Google Analytics Block Spam Bot Referral Traffic

Next, click the + NEW SEGMENT button, and enter a name for the segment, such as “Remove Referral Spam.” Then go to Advanced > Conditions on the left side of the menu, make sure it’s set up to Filter, Sessions, and Include on top, and then select Hostname and Matches Regex and simply use the expression that you already created above.

Finally, set up another new segment by clicking + Add Segment and simply ticking the All Sessions box. Scroll down, hit Apply, and then compare the two segments to ensure that your new segment is removing spam traffic from your historical data, as shown in the screenshot below.

Google Analytics Two Segments Remove Spam Referral Traffic

6. Exclude any remaining bot traffic by editing your .htaccess file

All of the above will work for the majority of spam, known as “ghost referrals.” But for certain web crawlers such as Semalt or, in our case,, you can stop the spam at your server. You could also set up a filter in Google Analytics, but we’d prefer to simply add the following to our .htaccess file:
# block semalt
RewriteEngine On
RewriteCond %{HTTP_REFERER} semalt\.com
RewriteRule ^.* - [F,L] # block bfw
RewriteEngine On
RewriteCond %{HTTP_REFERER} buttons\-for\-website\.com
RewriteRule ^.* - [F,L]

If you have a lot of those bots to block, there’s probably a more efficient way to code that, but this works for our purposes. Check out this forum post if you need to add a huge list of bots to your .htaccess file. By the way, your .htaccess file should be accessible if you have FTP access. If you don’t know if you do, you might want to contact someone from your IT department, or do a quick Google search.

We hope that helps you to get your analytics data cleaned up, and be sure to let us know if you have any questions, comments, or suggestions in the comments below!

Roshni Isaac
Roshni Isaac
Roshni is passionate about all things analytical: dreaming up different ways of using analytical techniques to improve businesses is what keeps her up at night! She has extensive experience in the field of digital analytics and conversion rate optimization. Feel free to email her with any questions related to analytics and optimization.