This method assumes that you meet the following conditions;

  • You can customize tracking codes of Google Analytics.
  • You have Manage Users permission for the property you are working on.
  • You use Universal Analytics(new version of Google Analytics).
  • You have not used up all your custom dimensions. ( if you have created 20 custom dimensions, you cannot add new ones, unless you are a Premium User.)

I think this method is feasible in almost all cases, since these conditions are not difficult to meet.

Steps for implementing this method

Step1: Add a custom dimension to the property

First, you add a custom dimension to the property. The name might be something like "Referrer Spam Filter" and the scope might be "Session".

For procedures for adding custom dimension to a property, refer to Google Analytics official help "Create and edit custom dimensions and metrics".

Step2: Assign value to custom dimension.

As a next step, you edit the tracking code and assign a value to the custom dimension.
For how to edit tracking codes, refer to Google Analytics official help, "Custom dimension & metrics", paragraph "Collection".

Normally, you assign an appropriate value for each user or session. But in this case, you assign a fully fixed value. And the value can be any string.

For example:

ga('set', 'dimension1', 'SEM Technology Referrer Spam Filter');

If you use Google Tag Manager, set this value in custom dimension when you fire Google Analytics tracking tags.

Step3: Add Filter to the View

As a last step, you add a filter to the View on the Admin page The filter configuration might be as follows:

name configuration value
filter name Block Referrer Spam
filter type custom, match
filter field Referrer Spam Filter
filter pattern SEM Technology Referrer Spam Filter
  • Note1: filter name may be changed.
  • Note2: filter field should be the name of custom dimension created in Step1.
  • Note3: filter pattern should be the value assigned to custom dimension in Step2.

How can referrer spam be blocked by this method?

Most instances of Referrer Spam do not actually visit your web site. In reality, they generate randomized tracking ID’s and send them to Google Analytics by Measurement Protocol. They have prima facie genuine parameters, like page path, referer, browser, language and others, so they cannot be filtered correctly based on parameters. But by using custom dimension, you can identify correct tracking data, because correct tracking data contains the fixed string, whereas referrer spam does NOT.

Is there any referrer spam which cannot be blocked in this way?

As a conclusion, some instances of referrer spam still remain even with this method. The following instances of referrer spam have been found on this site:


These instances of referrer spam actually visited this web site. I confirmed it on my web server logs.

It is difficult to block this type of referrer spam which actually visits your site. But this method can block almost all instances of referrer spam. In fact, this site has had only 23 sessions of referrer spam in 6 months.

If you implement Google Analytics tracking code by Google Tag Manager, you can check by referrer host name if the referrer host which actually visited your site is a referrer spammer.
And, you can configure it so that you stop firing Google Analytics tracking code or assign a different value in custom dimension if the referrer host is a referrer spammer.

More specifically, if you set variables and rules as follows, you can control conditions for firing Google Analytics tags.

Variable for containing the referrer host name

Lookup table for identifying referrer spam

Rules specifying how to respond when the host is not a referrer spammer

Since the filter is shown as a lookup table, you can easily grasp the filter configuration even when the number of referrer spammers has increased. (Unfortunately, it is difficult to tackle different varieties of referrer spam, because the lookup table does not accept regular expression.)


If you are thinking about anti-referrer spam measures and you don't want to create many filters, I recommend you this method.