We love digital - Call
0330 353 0300Circle Info
and say hello - Mon - Fri, 9am - 5pm

Call 0330 353 0300Circle Info

Koozai Koozai

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

Do you love Digital?

Get in touch - we're hiring!

What do you think?

Sophie Roberts

Kooznews: December 2021

Sophie Roberts
2nd Dec 2021
Hannah Pennington

DIY Digital Strategies: Are They A Mistake?

Hannah Pennington
29th Nov 2021

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?

Unlike 08 numbers, 03 numbers cost the same to call as geographic landline numbers (starting 01 and 02), even from a mobile phone. They are also normally included in your inclusive call minutes. Please note we may record some calls.

Circle Cross