Do you want to block WordPress referrer spam in Google Analytics?
Referrer spam sends misleading data to your website to pollute your website’s analytics reports with spam links.
In this article, we’ll show you how to block WordPress referrer spam in Google Analytics effectively.
What is Referrer Spam in WordPress and How Does It Affect Google Analytics?
Referrer spam in WordPress is a common spamming technique where fake traffic data is sent to a WordPress website.
This spam technique aims to pollute a website’s analytics data with spam URLs, keywords, and domain names.
It affects your Google Analytics reports as this data appears under Referral data and may affect your website’s overall page views, bounce rates, and session reports.
If you are seeing many suspicious-looking domains in your Referral reports, then they are most likely spam referrers.
Blocking these spam referrals will improve your Google Analytics reports and ensure that your data is not polluted by spam requests.
That being said, let’s take a look at how to easily block referrer spam in Google Analytics on a WordPress website.
Note: If you’re new and haven’t setup Google analytics properly, then we recommend using our guide on how to install Google Analytics in WordPress.
Block Referrer Spam in Google Analytics with Sucuri
This is the easiest way to block the most common referrer spam in Google Analytics.
For this you’ll need Sucuri. It is the best WordPress security plugin and comes with the best website firewall on the market.
It blocks most common website threats including referrer spam before they even reach your website.
Sucuri also comes with website monitoring, malware scanner, integrity check, and dozens of security features. This protects your website against hacking, malware, and brute force attacks.
Manually Blocking Referrer Spam in Google Analytics With a Plugin
If you are not using Sucuri, then you can use this method to check referral traffic and block them.
First, you need to install and activate the Stop Referrer Spam plugin. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation, you need to visit the Settings » Referral Spam page to review plugin settings.
The plugin uses a referral spam blacklist published by Matomo (Formerly Piwik, an open source analytics software).
You can also enter any suspicious domains that are already spamming your Google Analytics reports.
Don’t forget to click on the Save button to store your settings.
Be careful when adding domains in the plugin settings, as it will block all traffic from that domain name, including sub-domains.
3. Filter Out Ghost Referrers in Google Analytics
The first two techniques mentioned above will block referrer traffic that arrives at your website.
However, spammers may sometimes not send referral requests to your website. Instead, they would target your Google Analytics tracking code to trick it into recording a spam request.
These attempts will bypass filters on your website and may still appear in your Google Analytics reports.
You can filter these ghost referral spam in your Google Analytics account.
1. Block Unwanted Referrals in GA4
If your website is using Google Analytics 4 (GA4), then you can use the following method to remove unwanted referrals.
Simply log in to your Google Analytics dashboard and switch to the Admin view.
From here, under the Property column, select the Data Streams option. This will bring the Data Streams connected to your Google Analytics property.
After selecting your data stream you’ll see different settings. Simply scroll down to the Advanced Settings section and then click on the ‘More Tagging Settings’ tab.
Next, click on the ‘List Unwanted Referrals tab.
This will bring you to the configuration screen.
Under Match Type, choose ‘Referral domain contains’, and then add the domain you want to block next to it.
Click on the Add condition button to add another domain if needed.
Once finished, click on the Save button at the top right corner of the screen to save your settings.
Google Analytics will now exclude these referrals from your reports.
2. Block Unwanted Referrers in Older Google Analytics
If you are still using older Google Analytics account that uses the Universal Analytics (UA Tracking) code, then you can use this method.
Simply switch to the Admin view under your Google Analytics account.
From here, you need to click on the Filters option under the ‘View’ column.
This will bring up the Filters screen. Go ahead and click on the Add Filter button.
On the next screen, you can configure your filter settings.
First, you need to switch the Filter Type to ‘Custom’ and choose the ‘Exclude’ method.
After that, click on the ‘Filter Field’ drop-down and select the ‘Campaign Source’ option (this is where your filter will look for the match).
Lastly, add the domains that you want to block under the Filter pattern box in the following Regex Expression format.
Notice how the domain name and extension are separated by a backslash and a dot (\.), and each domain name is separated by a pipe sign (|).
The last domain in the list has a dot and asterisk (.*) before the domain name. This asterisk blocks not only the domain name but also all its subdomains.
Go ahead and click on the Save button to store your filter settings.
Google Analytics will now remove these spam referrers from your reports.
Filters don’t affect on how Google Analytics collects data on your website. They just customize reports you view in your Google Analytics dashboard.
If you need to, you can always return to the filters screen to edit or delete a filter.
We hope this article helped you learn how to block referrer spam in Google Analytics effectively. You may also want to see our ultimate conversion tracking guide for beginners or how to properly setup eCommerce tracking on your website.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
If i click on add a new filter, i only get the option to make an “exclude” filter. I don’t see the option to select a “include” filter like in the screen shot at this article. How is that possible?
Thank you for providing such helpful information, keep up the good work.
I think that this is not good. The best is to reject and block all these spam referrers because they cause to increasing the bounce rate. The problem is not in seeing them in the reports . The problem is how to block visitors from that spam referrers .
Oyekunle Damola says
Hello, you talked about the Regex string as ^wpbeginner.com$|^videos.wpbeginner.com$|^example.wpbeginner.com$
Other tutorials I have seen use this format -> wpbeginner\.com
So which is correct?
WPBeginner Support says
Both are correct.
This is exactly the information I have been looking for! Thank you!!!
Editorial Staff says
I agree with Mickey, the easiest way to get rid of those referrer spam is to filter out in Analytics all the requests for which the hostname is not the URL of your blog. Almost all the referrer spam don’t fill up this field, leaving it empty.
Maintaining a list is painfull since there are always some new comers in the game.
I agree with Mickey, the Referral Exclusion List t seems to be a bad idea.
I agree with Mickey. You need to include valide host name in Google Analytics filters and it will block all the rest. Like that you don’t have to worry about future spam to exclude. And you certainly don’t need any plugin.
As Mickey mentioned above, using the referral exclusion will hide the problem as visits will be treated as Direct. Please, change the recommendation to using filters instead.
WPBeginner Support says
Thanks Ruth, we have updated the article with more accurate method of setting up filters.
Sagar Nangare says
Very nice article on very important issue causing lot of damage to reporting.
Cindy Peterson says
LOL I have just found out the majority of my “traffic” was spam. Sigh. Thanks for the advice. I have downloaded the plugin & added the spammers to my google analytics.
The Referral Exclusion List tip is a bad idea; that will simply treat them as “direct” visits and continue to muck up your Analytics. The better move is to set up a filter that relies on valid hostnames and blocks the rest. Here’s a video that shows how to do it:
WPBeginner Support says
Update: We have updated the article with more accurate method of creating a filter for valid hostnames.Thank you for suggesting it.