Last weekend, I wrote a very simple web app that automatically creates a number of referral spam filters to tackle the problem that seems to have everybody all riled up.

For a nice recap of the situation, take a look at this post by Jeff Sauer, or this article by Mike Sullivan.

This isn’t an opinion piece, even though I’ve got a great number of opinions about this issue. If you want to read some discussion surrounding this, take a look at this Google+ thread.

(UPDATE: I have taken down the demo tool. You can still download the source code below if you wish, but there are more robust ways to block GA spam than creating an individual filter for each referral.)

The tool is called the “Spam Filter Insertion Tool”, or SFIT for short (I dare you to start using that in your everyday lingo).


The Simmer Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava into your email inbox!

Download the source code

The real meat of the solution is in the GitHub repo.

You can download the source code, install the application on your own web server, and use it for your own purposes.

The application has access to the following features of the Google Analytics Management API:

  • READ the list of accounts, properties, and profiles you have access to

  • INSERT or UPDATE profile filters on the account level

  • INSERT profile filter links, which attach the newly-created or updated filters to the selected profiles

To get it up and running, you will need to register a new project in the Google Developers Console, create a new Client ID for a web application, as well as a public API key. Remember to activate the Google Analytics API as well!

How it works

When you click Initialize, the tool requests your authentication to do all sorts of horrible things to your GA account. Do not worry! This tool mainly only INSERTs and READs. The only exception is if you already have these spam filters installed on your GA account, but they are outdated, in which case the tool will automatically update them to their newest versions!

Once you’ve authenticated your account, you will be served a drop-down menu from which you can choose any GA account you have EDIT access to. Why EDIT access? Because that’s the required access level for new filter creation. You read that right! To create filters, you need EDIT access on the account level.

Anyhow, choose an account and the tool should shortly load with a multiple selection menu, where you can pick the profiles to which you want to link the filters.

Once you click the Create and apply filters, the tool does just that. First, it creates the filters on the account level, after which it links each filter to the profiles you selected.

The list of filters is the one maintained in this Lone Goat resource. Whenever they update the list, I update these filters. Which brings me to the…


These filters only help with referral spam. They will not help you with polluted Measurement Protocol hits, or with spam that doesn’t come in as referral traffic, or with spam that comes in as referral traffic but isn’t in the filters yet. There are many methods to combat this issue, and you might want to check the couple of links I had in the very beginning for ideas.

Anyway, feel free to use the tool and let me know if there are issues.