The Rise of Spam in Google Analytics

Most of us have some passing knowledge of what Spam is; it’s been the bane of all of our lives at one time or another.

But, when it comes to Google Analytics,  Spam come in a form of referral traffic through bots and it can account for a few hundred sessions a month, giving the data an artificial spike.

Garbage in Garbage Out

On a small site, a few hundred visitors a month can account for up to 80% of the traffic to the site, suffocating legitimate visitors and making market analysis incredibly tricky.

If that sounds frustrating to you, never fear: there are several ways you can work around this Spam data in your Google Analytics.

Spam Referral Traffic - GA

.Htaccess

The best way to stop Spam is to block it in the .htaccess file in the root directory in your domain for Apache Server, which prevents Spam bots from hitting your site entirely.

# Block Referrer Spam
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://.*get\-free\-social\-traffic\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*floating\-share\-buttons\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*event\-tracking\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*success\-seo\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*free\-floating\.buttons/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*video\-\-production\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*get\-free\-traffic\-now\.com/ [NC,OR]
RewriteRule ^(.*)$ – [F,L]

Note: if you see any new spammy referral present, you just have to add in the list for each new line with the URL format with . – escape by \ as it is matched using regular expression.

Warning: .htaccess is a very powerful file that instruct how your server behaves but 1 Error in .htaccess file will bring your whole site down.

Google Analytics Filter

If you are unfamiliar or uncomfortable on touching .Htaccess files, you can implement Google Analytics Filter. But take note that using this method , you can only be blocking future sessions.

Using this method, it will filter future spam referral out from your Google Analytics data.

1) To implement this, start off by copying the unfiltered view. (*It is always recommended to have an unfiltered view as you will not be able to get back data that is filter out anymore.)

GA - Copy View

2) Give it a meaning name for the new view. Example “No Spam Referral“.

Next, we will need to give 2 Filter conditions that is common with Referral Spam, Hostname and Campaign Source.

Start off by going under “Filter” in the new View we just created.

Choose “Custom” for Filter Type and in the Filter Field, choose “Hostname“. In the Filter Pattern, enter your domain URLs.

The pipe character “|” means OR in this case and also include in googleusercontent and click on “Save”. (Hostname use for Google Translate & Web Cache of your Site by Google)

*Note: Any . or -, have to be escape by \ as we are matching using Regular Expression. In our case, digitrio\.com\.sg.

Hostname Exclusion

3) Next, we will need to setup another filter to capture spammy campaign source. Go under the same view, Filters -> New Filter. Give it a meaningful name and in our case “Exclude Spammy Sources“.

Under the Filter Pattern, copy and paste the following:

offer|free\-|share\-|mercedes|buy|cheap|semalt|googlsucks|hulfington|buttons| darodar|pistonheads|motor|money|blackhat|backlink|webrank|seo|phd| crawler|anonymous|\d{3}.*forum|porn|webmaster|flipboard|fl\.ru|
 mbca|ahrefs|game|\.io|sexyali

Exclude Spammy Sources
Note: if you see any new spammy referral present, you just have to add in the list for each new line with the URL format with . – escape by \ as it is matched using regular expression.

Filters are great and must have for removing spam referral moving forward, but if your Google Analytics is already filled with spam referral, the only way to exclude and analyze the data is using Segment in Google Analytics.

Segment

A Segment is a subset of your Google Analytics data. Eg, you can set a Segment to show only data from organic traffic.  The common segments are already built in Google Analytics and it can be accessed beside All Sessions and checking on the option you wish to see.

Segment - Google Analytics

To see our data with no spam, we will have to create a new custom segment for it.

1) Click on “Add Segment” and give it a meaning name, eg No Spam Referral. Click on “Conditions” and set it to “Exclude”. 

Next, choose “Hostname” with “does not match regex” and add in your “domain\.com|googleusercontent”.
(Replace domain\.com with your own and remember to add in \ for . or – in your domain URL)

Basically, we wanted to exclude any data that does not matches our domain or from googleusercontent domain (which might come from Google Translate & Google Cache)

GA Custom Segment - Step1

2) Click on “Or” to add in another conditions.

Next, choose “Sources” with “matches regex” this time.

Add in the following regular expression formulate to matches with spam referral domain:

offer|free\-|share\-|mercedes|buy|cheap|semalt|googlsucks|hulfington|buttons| darodar|pistonheads|motor|money|blackhat|backlink|webrank|seo|phd| crawler|anonymous|\d{3}.*forum|porn|webmaster|flipboard|fl\.ru|
 mbca|ahrefs|game|\.io|sexyali

Custom Segment - Google Analytics

Note: The difference between a Segment and a Filter is that the first one takes a part of your stored data based on the conditions you apply without actually deleting any data, while a filter will stop future data from even being stored, but all previous data entries will still be there.

Conclusion

The above 3 methods are work to achieve the same result and we definitely recommend to go ahead with implementing Filter & Segment methods especially if you are not savvy in web development as a mistake in .htaccess can bring down the whole site. If you want to learn more about Regular Expression, Brian Clifton has a quick & easy article to help you jumpstart on it.

Google Analytics is one of the best free tool to understand your website traffic data but it is only useful when it is free from all these spam data. So if you are noticing all these spam referral data appearing in your Google Analytics, give the above methods a try.

Leave a Comment