We're hiring

Call 03332 207 677

Jack Evershed

How To Stop Referrer Spam in Google Analytics

10th Sep 2015 Analytics 2 minutes to read

How To Stop Referrer Spam in Google Analytics

The fight against referrer spam has long been a losing battle. It seems like every time a ‘solution’ is found, the spammers are already a step ahead, like a never-ending game of Whack-A-Mole.

A lot of people make the mistake of trying to block spam by using server solutions like the .htaccess or plugins. These will not work as this type of referral never visits your site and is merely fake data.

The spammers generate UA codes at random and send the fake data directly to the Google Analytics server via the back-end ‘Measurement Protocol’.

It’s a pretty ingenious way to annoy people and get affiliate traffic en masse, but there is one inherent flaw – as the UA codes are random there is no way of knowing what your particular hostname is.

You can exploit this flaw by implementing a ‘Valid Hostname Filter’. It is the simplest and most effective solution out there.

I’ve been giving these instructions to clients for the last few months and it seems to work very well. Let’s hope it lasts.

Here’s how to do it:

To find out your valid hostnames:

  • Go to the Reporting tab on GA and select the biggest timeframe possible on the date range.
  • In the lateral bar, select Audience
  • Expand Technology and select Network
  • At the top of the report, make sure you select Hostname because Service Provider is selected by default.
  • Find and copy all the valid hostnames.
  • Your valid hostnames will include all the places where you put your tracking code (UA-XXXXXX-1), such as yourdomain.com, yourdomain.com, blog.yourdomain.com.

How To Stop Referrer Spam

You can see from the example above that you may also have services in which you add your tracking ID, like an ecommerce provider, or in this case, a translation service for an international audience.

You may find official-looking hostnames like amazon.com, or even google.com, but these are planted there by spammers to deter you from removing them so your account can continue to be spammed.

Once you have this list, you will need to build a REGEX – don’t be put off by the scary name, it’s really easy. Just use the ‘|’ character to separate your domains.

This is the REGEX for the above example:


To create the filter:

  • Go to the Admin tab and create a new view in the property.
  • Select New Filter.
  • Select Create New Filter and enter Valid Hostname Filter as a name.
  • In Filter Type select Custom.
  • Make sure you choose Include and select Hostname from the dropdown.
  • Finally, paste the REGEX that you built with your valid hostnames in Filter Pattern.

Verify the filter and you’re done!

How To Stop Referrer Spam

Always remember to create this filter in a new ‘view’ so you have something to compare the data to. Unfortunately this won’t work retroactively unless you know how to use custom segments, but with the new view there will only be the new data anyway.

If you’ve got any thoughts, please feel free to write a comment, or if you need some help you can reach me directly via @Jack_Evershed on Twitter.

Share this post

Jack Evershed
About the author

Jack Evershed

Straight-talking Jack is a bit of a know it all so be prepared for an all-out banter battle if you challenge his common knowledge – though he would make an awesome pub quiz partner. The whiskey-drinking, laid-back geezer will have you cracking up with his dead pan delivery and telling you exactly as it is.

Analytics Whitepaper Cover

Free Whitepaper The Complete Google Analytics Guide For Business

What do you think?

  • aspect-ratio Samantha Noble at Voice FM
    Cat Birch

    Samantha Noble Shares Paid Media Insight on Voice FM

    Last month, we tuned in to listen to our very own Samantha Noble become a radio star. As a guest on Xan Phillips’ The Business on Voice FM, a programme dedicated to promoting the good news stories about business from the Southampton area and beyond, Sam shared her insights into paid media.

    Cat Birch
    18th Jan 2017
  • aspect-ratio Create Britain
    Cat Birch

    Koozai Supports The Drum Network and Their ‘Create Britain’ Initiative

    The Drum Network has launched a new initiative called ‘Create Britain’ which aims to show the world that Great Britain is still an awesomely creative marketplace, despite Brexit.

    Create Britain is an online interactive map that invites businesses from the creative industry to contribute a short video to claim their own pin on the map that links to their video clip. The video clips need to answer one question: ‘What makes British creativity so great?’.


    Cat Birch
    13th Dec 2016

Digital Ideas Monthly

Sign up now and get our free monthly email. It’s filled with our favourite pieces of the news from the industry, SEO, PPC, Social Media and more. And, don’t forget - it’s free, so why haven’t you signed up already?