We're hiring

We love digital - Call
03332 207 677
and say hello - Mon - Fri, 9am - 5pm

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 Koozai at Search Elite
    Cat Birch

    Koozai Sponsors Search Elite 2017. Plus, win a free ticket!

    We are pleased to announce that Koozai will be sponsoring Search Elite London! (more…)

    Cat Birch
    20th Mar 2017
  • aspect-ratio Sam judging awards
    Cat Birch

    Samantha Noble Judging MENA Digital Awards, DANI Awards And UK Biddable Media Awards

    Samantha Noble is well known within in the search industry, she even won the UK Search Personality 2016 at the UK Search Awards in November. This year, she continues to make an impact on the industry by judging not only one, but three, prestigious industry awards.

    Cat Birch
    8th Mar 2017

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?