If 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 makemoneyonline.com are included in my stats.
What gives, and how do you fix it?
What is going on?
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.
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:
On the next screen, you want to click the Filters link in the left column:
Next, click the New Filter button, which looks like this:
On the Edit Filter page, you will need to use the following settings:
- Filter Name = Give your new filter a name, like “Protect Analytics”
- Filter Type = Select Custom
- Click the Include radio button
- Filter Field = select Hostname in the pulldown menu
- 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$
- Make sure Case Sensitive is NOT checked
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!