Spam sucks. It sucks in your inbox. It sucks on Twitter and Facebook. It sucks as a canned meat (Ok, it’s really not that bad). But it especially sucks in Google Analytics.

Google Analytics (GA) is foundational for any website and the data gleaned for UX, SEO and a lot of other things is extraordinarily valuable. So, if your data is dirty, you might make decisions that you wouldn’t have otherwise. Not to mention it’s annoying as hell.

Luckily there are a few ways to kick GA spam to curb and save your sanity. Did i mention spam sucks?

Setup Filters

Filters make it pretty easy to filter out traffic from certain domains, countries or to hostnames. If you’re unfamiliar, go to GA > Admin and you’ll see the screen below.

Filter view

You’ll notice 2 areas for filters. On the left is for the entire Account and the right is just for a certain view. For referral spam I like to use the Account level filter to avoid repeating filters across views.

Account level filter google analytics

Ok, now that we know where filters live, let’s add one.

  1. Select Filters
  2. Click + New Filter
  3. Give your filter a name like Referral Spam Destroyer
  4. Select filter type of Custom
  5. Click the Exclude radio button
  6. Select the Filter Field of Referral

For the next step, I like to use regular expressions. This avoids adding a bunch of exclude filters for each spam referrer. It also makes it pretty easy to add a new spam domain when you spot it. And if you set it at the account level, it’ll add it to all views.

  • Add the below to the Filter Pattern


Copy it all and click Save.

To add new domains, just add a ‘|’ along with the domain (no subdomain or TLD).

You can also use the above method to stop direct traffic spam to random hostnames. Simply select Hostname instead of Referral and follow the steps.

Referral Exclusion List

If you aren’t comfortable with RegEx, then you can add each referral domain in the Referral Exclusion List in the Admin section.

  1. Go to Tracking Info under Property
  2. Click Referral Exclusion List
  3. Click + Add Referral Exclusion
  4. Click Save

This will do the same thing and exclude referral traffic for the views, just a bit tedious IMO and can’t be copy/pasted easily like the above RegEx filter.