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:
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:
Verify the filter and you’re done!
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.