Stop Google Analytics Referral SpamIf you have a web site, you’re probably using Google Analytics to track traffic to your site.

Overall, Google Analytics is pretty cool. In fact, for most people, it’s too cool. It does a whole lot, but that means it’s rather complicated for the average user to set up properly.

You may have noticed in your site stats on GA that there are some wonky domains showing up.

For example, instead of GA reporting traffic from ScottiesTech.Info, mine shows me that domains like are included in my stats.

What gives, and how do you fix it?

What is going on?

This kind of “spam” is usually called referral spam. Basically, spammers take the GA JavaScript code, substitute your GA ID number in, and plop the code on their pages. This is perfectly doable, since I can very easily look at the HTML source of your web site, grab your GA include code, and stick it on my web site.

Once they do this, they or someone else visits their page with your GA code. Poof! Suddenly, their domain is showing up in your GA stats.

But why?

The idea here apparently is that you will see their domain, and go investigate, thereby driving traffic to their site. There are of course other more nefarious reasons for a spammer to drive you to load their site…

I’m surprised Google doesn’t have a little “wizard” to remind you to set up a domain filter right off the bat when you first launch your GA account and set up your site. But, they don’t. SIGH!

Fortunately, it’s very easy to tell GA to only track pages that use your Google Analytics ID when those hits happen on your domain.

Stop Referral Spam

This only takes a few minutes to set up, and it’s very easy. First, you want to log in to Google Analytics, and go to the Admin page. Once there, you click the View Settings link in the View column:

Stop Referral Spam - Step 1

On the next screen, you want to click the Filters link in the left column:

Stop Referral Spam - Step 2

Next, click the New Filter button, which looks like this:

Stop Referral Spam - Step 3

On the Edit Filter page, you will need to use the following settings:

  1. Filter Name = Give your new filter a name, like “Protect Analytics”
  2. Filter Type = Select Custom
  3. Click the Include radio button
  4. Filter Field = select Hostname in the pulldown menu
  5. Filter Pattern = here you enter the regular expression that will match the domain(s) you want to include in your Analytics. In the example below, I use:  ^(www\.)?scottiestech\.info$
  6. Make sure Case Sensitive is NOT checked

Stop Referral Spam - Step 4

If you’re not up on your regex, don’t worry. The following regular expression is rather simple:


  • ^ means match the start of the string
  • (www\.)? means that either www. can be in the hostname, or not
  • scottiestech\.info matches my hostname (replace with your own)
  • $ just means the end of the hostname; no more characters are allowed

Now, before you click the Save button, first click the Verify this filter link. That will give you an idea of the Evil Hostnames/Domains that will be removed by your new filter.

When you’re sure everything’s okay, Save the filter. You’re done!

If you have multiple subdomains, you can use a different regex like so:


That regex would allow only:


Note that if you screw up the regex Filter Pattern, you may end up filtering all the valid stats coming from your site, so be careful and double-check your typing.

Now, just sit back and enjoy clean Google Analytics stats without any referral spam!

Need help? Hire me!
Get Scottie Stuff!