How to block referrer spam with Google Analytics filter

The most effective way to block ghost referrer spam from accessing your website and affecting your analytics data is to set up a custom filter directly in your Google Anaytics account. To find out if your website is affected read our blog post Is referrer spam affecting your website metrics?

Set up a View in Google Analytics

Before you can begin to use any of the techniques below we recommend setting up an additional view in Google Analytics. The benefit of views is that you can see the effect any filters you have applied are having by comparing data across filtered and unfiltered views.

By default, Google Analytics automatically creates one unfiltered view for every property in your account. This ‘raw’ unprocessed view is one in which the data has not been modified by filters. If you only have one view in your property, you will first need to create an additional view. Select the Admin tab and navigate to the account and property to which you wish to add the view. In the ‘View’ column, click the dropdown menu, select ‘Create new view’ then follow the on screen instructions. When you create a new filter using the procedures below, make sure you select your newly created view.

Filtering Ghost Referrers

Ghost referrers are visits that show up in your analytics account for visits that never actually took place. Instead of visiting your website the ghost referral is sent directly to Google’s Analytics servers. You can identify these requests by looking for any visits that do not include your hostname as their destination.

Reporting > Audience > Technology > Network > Primary Dimension: Hostname

analytics hostname-block referrer spam with google analytics

Make a note of any valid hostnames where you have installed your Google Analytics tracking code. In most cases this would be your domain and any subdomains, for example for our website this would be

In Google Analytics go to Admin > Select View > +New Filter > Create New Filter > Enter ‘Allowed Hostnames’ as filter name > Select Custom Filter type > Choose Include > Choose Hostname from list > Enter a domain name in filter pattern, ‘’. Click Verify this filter > Click Save.

block referrer spam with google analytics

Please note that filters can take up to 24 hours before they are applied to your data. Check back in a few days and don’t forget to set the data range in your reports to include only new data since the change.

We recommend you also block referrer spam from accessing your website directly by using an .htaccess file or WordPress plugin – see the links below. Please note that other methods may be applicable depending on your hosting platform and content management system.

Related blog posts

Is referrer spam affecting your website metrics?
How to block referrer spam with a WordPress plugin
How to block referrer spam with an .htaccess file

Grow your business faster with strategic, results driven digital marketing.

Let’s get started

Our industry expert

Nigel Reece

Managing Director

Standing at the helm of Cognique, Nige is a strong believer in the value of professional networking and strong business relationships. He also still finds time to exercise his creative muscles, designing attention-grabbing brand guidelines and concept boards for our clients.

Nigel Reece profile photo

Is now the time to start dominating online?

Let’s get started

Subscribe to our newsletter

Join over 600 like-minded individuals who benefit from our monthly roundup of marketing insights, tips and updates.

"*" indicates required fields

What are you interested in?
This field is for validation purposes and should be left unchanged.