How To Stop Referral Spam In Google Analytics
In order o stop all Ghost Spam, instead of excluding each of them in an "Exclude Filter" it is best to INCLUDE all of the valid domain/hostnames that you WILL accept in an "Include Filter" and this way anything other than will not get through or attack your website.
This "Include Filter" works for all of the different traffic channels/categories, not just for the Referrals category because ghost spam attacks all categories.
Create An "Include" Filter in GA To Stop Ghost Spam
Step 1. If not signed-in to GA, go ahead and do so.
Step 2. At the top menu click on the “Admin” tab and select “View”.
Step 3. Select “Filters” and choose “Create New Filter”.
Step 4. For Filter Name enter “Include Valid Hostnames”.
Step 5. Then for Filter Type select “Custom”.
Step 6. Then choose “Include” and for the Filter Field choose “Hostname” from the dropdown menu.
Step 7. In Filter Pattern, paste the REGEX pattern that you created.
Step 8. Verify if the filter works. In Filter Verification click on “Verify this filter”. You should then see 2 columns, a before and after. The "after column" should be empty.
Note that if the "after column" is not empty then there is an error or problem with the REGEX pattern and you will see an error message at the top. It must be fixed and corrected before you save the filter or it will not work.
Step 9. If the "after column" is empty, click “Save” and your done!
Keep in mind that if you’re going to be including your Tracking-ID for a service, that you will need to include that hostname in this "Include Filter" so that GA counts it as valid incoming traffic. Other than that, you don’t need to keep any maintenance on it.