To make it easier to follow I split this guide into 4 parts. The first 2 are practical, the last 2 are informative:


Analytics advocate

SEO expert

User Experience passionate

Follow me on
Category | Google Analytics
Difficulty |

Filtering Google Analytics spam, bots, and other junk traffic: A comprehensive solution!

Stopping spam and bot traffic is a must if you want to receive clean and reliable data in your Google Analytics. However, despite being one of the most useful and recommended configurations in GA, I'm still surprised to see that many of the Analytics properties I audit either don't use filters at all or they do but in the wrong way, which make things worse and its maintenance a nightmare.

  • Fortunately, if used well the powerful GA filter functionality can efficiently help you prevent all junk traffic,
  • Unfortunately, there is no one all mighty filter that will stop all spam and bots at once, so you will have to work a bit if you want to keep your data accurate.

To avoid wasting your time on partial/wrong solutions and help you get the best data possible I will show you:

  • The most efficient ways of filtering junk traffic in your Analytics,
  • And also important, how to do it safely so you don't risk your real user data.

A quick FAQ about this guide

To save you some time looking through the comments, here are the answers to some of the most common questions I get:

  • Which type of spam and bots does this guide cover?
    • All of them! The filters will help you understand and stop any type of Google Analytics spam: Ghosts (referral, keyword, language, page, etc.), crawlers and many known bots,
  • Does this work in WordPress, Joomla, Shopify, Wix, Weebly, Squarespace...?
    • Yes. The solutions below are purely based in GA filters, so it will work independently of the platform (CMS) you use.
  • How often do you check for new threats and update the expressions?
    • I'm constantly monitoring for new spam and bots (almost daily) and the expressions are updated as soon as new significant threats are detected, so you can check them frequently or even better you can get notified when new expressions are out.
    • See the historical spam blacklist blocked by these filters.
    Want to get notified of important updates, new threats, and new ways of keeping your Analytics data accurate?

Dos and don'ts when filtering spam in Google Analytics

Let's start with what you shouldn't do. (If you made any of the mistakes below, undo the changes)

How does Ghost Spam attacks Google Analtyics?

First things first. Protect your data from misconfigurations

Before creating any filter in GA you have to make sure you have at least 2 views, one were you will apply the filters and a second one that you will leave unfiltered, this will work as a backup and to check the progress of your filters.

If you need help creating these views, here you can find the best practices for views in Google Analytics.

5 filters to stop spam and bots in Google Analytics

Once your views are correctly configured, is time to stop all of that dirty traffic that skews your reports and don't let you see the real performance of your site.

The filters I'm going to show you have been proven to work for over 4 years regardless of the methods used by spammers.

Need some proof? Here are some examples of users that followed this guide and shared their results with me. Show Examples

The screenshots are from 2016 but the results for your analytics will be the same to this date.

The Google Analytics filters you will need are:

  1. Valid hostname filter for ghost spam (referral, page, keyword spam, language, etc.),
  2. Campaign source filters for crawler referral spam,
  3. Language filter for sneaky spam (and some bots),
  4. ISP organization filters for bot traffic,
  5. ISP domain / Network filter to stop bot traffic,
  6. Extra: Enable the built-in feature "Bot Filtering" (to exclude a few known bots)

Don't have the time? Want me to fix this for you? I can review your analytics and apply all the necessary measures to ensure you are receiving the most accurate data possible.

General notes about filters.

  • While most of the time filters start working within minutes, officially it may take up to 24 hours before the filter effects become visible in your data, so be patient.
  • You will apply the filters either in the master view, the view(s) to be used for analysis, or the test view if you want to try them first.
  • Filters only work forward, for historical data you will use the segment.

a. Valid hostname filter to stop ghost spam

The valid hostname filter is the single most effective solution against the spam. This filter will permanently stop all ghost spam with fake hostnames no matter how it comes or what name it uses.

Google Analytics spam filter
What is a hostname vs a source? expand

People often mistake hostnames with sources. To avoid confusions while preparing the filters, I'll briefly explain the difference:

  • The Source is where your visit comes from and there can be any number of them, for example, Facebook, Google, Twitter, Youtube, links from other sites to your site, etc.
  • The hostname, on the other hand, is the site where the visitor arrives. Your main hostname will be your domain and, and depending on the configuration of your site, there may be others.
Source vs Hostname Google Analytics
To build this filter you will to:
  1. Make a list of your hostnames:
    • To see a list of all the active hostnames you need go to the Network report in your Analytics:
      • Audience > Technology > Network
    • Change the primary dimension to Hostnames  (blue text at the top of the report)
    • Make a list of all the valid ones you find. You should see at list one valid, which is your main domain, the rest will depend on the configuration of your site.
  2. Build your hostname expression: Once you have the list of all your hostnames, you should put all of them together separating them with a pipe "|" character like this:
    If you need extra help finding your valid hostnames and building your expression check this guide or let me know and I can personally help you.
  3. Create the filter: Once you are sure the expression is correct, create the filter as follows.

How to create a filter to block ghost spam in Google Analytics

To block all ghost spam in Google Analytics, you need to create an include hostname filter:

  1. Go to the Admin tab, and select the view where you want to apply the filter. If you follow the naming above, this will be the Master view or Test view.
  2. Select Filters under the View column, and select + Add Filter
    Add filter button Google Anlaytics
  3. Enter as a name for the filter Include Valid Hostnames.
  4. Configure the filter as follows:
    • Filter Type Custom > Include
    • Filter Field Hostname
  5. In the Filter Pattern box copy the hostname expression that you built before.
    How to filter spam in google analtyics?
  6. You can click on Verify this filter, and you will get a quick glance at how the filter will work. But take into account this feature is limited to a small amount of data. So you might get the following message:

    "This filter would not have changed your data. Either the filter configuration is incorrect, or the set of sampled data is too small"

    But don't worry, if you followed the instructions in the previous step (Build your expression) you already tested your filter, if for some reason you missed it, here it's again how to verify a filter with an in-table filter. ;)

  7. Once you make sure your filter is ok, Save the filter.

IMPORTANT: This filter doesn't require updates for new ghost spam, but it's essential to update the expression whenever you add the tracking ID (UA-00000-1) to a new service or domain.

b. Source filter to stop Crawler referral spam

Crawler spam uses a valid hostname so it is a bit harder to detect. To block it you'll need a filter with an expression that matches the source of all known crawler spam.

To save you some time, I've created a set of optimized regular expressions (REGEX) with all the relevant crawler spam detected over the last years, you'll find them below in the instructions.

How to create a filter to block crawler referrer spam in Google Analytics

To block referrer spam in Google Analytics you will need to create an exclude filter using the campaign source:

  1. Again go to the admin section of your GA.
  2. On the last column "VIEW", select Filters  and then click + Add Filter
    Add filter button Google Anlaytics
  3. Enter as a name for the filter "Exclude Crawler Spam"
  4. Configure the filter as follows:
    • Filter Type select Custom > Exclude
    • Filter Field select Campaign Source (don't use referral field or it won't work)
      How to block referrer spam in Google Analytics?
  5. Filter Pattern > Paste the following crawler referrer spam expression.
    These expressions were re-built to optimize the number of filters. If you created your filter before November 23, 2018, replace all the old expressions and remove any extra filter.

    Create 1 filter for each expression

    Crawler Expression 1


    Crawler Expression 2


    Crawler Expression 3


    Get free notifications with the updated expressions whenever I detect new crawlers.

  6. After everything is set Save.

Note: You may find other referrals that may not be spam, but neither relevant for you. For example, mobile test sites or cache sites. You can create a similar filter with the same configuration and add all the irrelevant referrals there to keep your data pristine and reliable.

Now that you are familiar with the filter window I won't repeat the full instructions on the following filters. To create them you will need to follow the exact same steps of the previous 2 filters and change the following fields:

  • Filter name
  • Filter field
  • Filter expression

c. Language filter for sneaky crawlers and bots

From time to time you may see weird languages showing in your analytics. I prepared an expression that will prevent any language that doesn't have a proper format like es-ESen-US, fr-FR, etc.

I also added to the expression the "Language c" which seems to be left by bots.

  • Create a new filter with the following settings:
    • Filter name: Exclude invalid languages
    • Filter configuration:
      • Filter typeCustom > Exclude
      • Filter field: Language Settings
      • Filter pattern: enter the following expression as it is:
        spam and language c google analytics

d. ISP organization/network filter to stop bot traffic

Not all irrelevant traffic comes from spammers, some companies use bots to crawl sites for different purposes (indexing, analytics, etc.). Those bots may not have bad intentions but they still pollute your data.

Here is an example:

google llc and the referral in Google Analyitcs
Another common example is if you use Facebook or Instagram ads. If you do you will notice some a considerable amount o bot traffic with the following characteristics.
  • Screen resolution: 2000x2000
  • Country: Peru, Philipines, United States
  • City: (not set), Quezon City, Manila
  • Service provider: Facebook Ireland Ltd

The following filter includes the following ISP organizations that are used mostly by bots.

ISP identified for using bots
facebook ireland ltd google llc google inc. llc ovh hosting inc. microsoft corp
microsoft corporation hubspot evercompliant ltd.
kazooisyee google switzerland gmbh google corporate
  • Create a new filter with the following settings:
    • Filter NameExclude ISP provider bots
    • Filter configuration:
      • Filter type: Custom > Exclude
      • Filter fieldISP organization
      • Filter pattern: enter the following expressions as they are:


        I extensively test the expressions below across dozens of GA properties to avoid interference with real user data. However, in very few cases the expressions could match some real user data.

        For example, the expression below blocks the ISP "Google llc" and "Microsoft corp", which are ISP used in these companies offices.

        In most cases the visits with those ISPs come from bots, however, they can also be used by employees, so if your site sells a product to those companies, just remove them from the expression. If you are not sure you can test the expressions before applying them to your GA.

        ISP Expression 1


        ISP Expression 2

        Filter google llc and in Google Analytics

e. ISP domain/network domain filter to stop bot traffic

This filter is similar to the previous one but this time we will target the ISP domain or network.

  • Create a new filter with the following settings:
    • Filter Name: Exclude ISP domain bots
    • Filter configuration:
      • Filter type: Custom > Exclude
      • Filter fieldISP domain
      • Filter pattern: enter the following expression as it is


This filter covers the weird amazon keywords from Bing organic traffic with network domain

f. Extra: Enabling "Exclude all hits from known bots and spiders"

This is a pre-built filter that will take care of known bots from the IAB bots and spiders list, it is not perfect but it helps.

In this case, is a bit easier than custom filters because you just need to check a box.

How to enable bot filtering

  1. Again in the Admin section of your Analytics, select your Master view under the VIEW column. (Also for any other filtered view)
  2. Click View Settings
    how to block known bots in Google Analytics
  3. Near the bottom check the box Exclude all hits from known bots and spiders (Bot Filtering)
    Exclude all hits from known bots and spiders
  4. Save and repeat the process with all your Views

What's next? Get even more value from Analytics data

  1. Clean spam from past data: The filters above will prevent future hits, here you can find instructions to clean spam from your historical data.
  2. Exclude internal traffic: This type of junk traffic is often overlooked. If you don't apply filters for the traffic generated by you or other people of your team, this data will get mixed up with your real visits data, and a difference with the spam, this is much harder to identify later.

Additional resources

Wrapping it up

Whether you are a blogger, a small local website, or a multinational company, filtering your data is crucial for the accuracy of your reports.

"Even on high volume websites were data spamming would be marginal, you still have to explain why there's such a discrepancy. As an analyst you can't dismiss it simply by saying "nah... we're not too sure what it is..."

-Stéphane Hamel

However, you have to do it right. Handling each spammer individually is time-consuming and inefficient. The Google Analytics spam filters explained in this guide may take a bit longer to configure but they will save you a lot of time in the long run.

I will be updating this guide as new threats appear so you can keep it as a reference.

Do you have any questions or feedback?

I've tried to cover every important detail in this guide, however, if there is any part of the guide where you got stuck, let me know in the comments section below.

If this article helped you, consider sharing it or leaving a comment below on your experience, it may help other people! :)need help implementing, configuring, and/or protecting your Google Analytics? I can help

Need help setting up a robust and reliable Google Analytics reporting for your website/business?

  • Filters for data quality
  • User interaction tracking (events, goals)
  • E-commerce tracking
  • GDPR compliance
  • Google Tag Manager implementation
  • Integrations (Google Ads, Search Console, etc)
  • Custom reports (Dashboards, Data studio)
  • Monthly reporting and more...

Analytics advocate

SEO expert

User Experience passionate

Follow me on
Be the first to comment :)