How to Stop Ghost Referral Spam In Google Analytics

4 minute read

What is Ghost Referral Spam?

Ghost Referral spam is fake interaction with your website that can easily throw off the accuracy of your analytics data causing you frustration and wasted time. Floating Share Buttons is an example of this and their ability to spam your analytics data from multiple sources or sub-domains makes it one of the most tedious to sort through. This Ghost Spam doesn’t actually visit your website, it only uses your analytics tracking code to affect your data. Regular methods to remove the sessions, such as editing the ht-access file, won’t work and it might have you calling someone who can bust those ghosts.

Don’t be afraid though. Luckily there’s a way to remove Floating Share Buttons and other Ghost Spams ability to affect your Google Analytics data and we’re about to show you how with a Valid Hostname Filter.

What Does A Valid Hostname Filter Do?

The Valid Hostname Filter is designed to stop all Ghost Spam, that means that other types of spam that directly visit your website might still be able to affect your data. Our goal today is to remove the Floating share buttons Ghost Referral Spam so let’s get started.

Even if you don’t have Ghost Spam yet you can use this guide as a preventative measure, protecting yourself from being slimmed by Ghost Referral Spam in the future.

Part 1: Separate The Good From The Ghosts

  1. Increase the timeline of your report by selecting a few months worth of data using the calendar drop down in the top right corner of the window.
  2. Navigate to the Reporting Section of the Google Analytics account you want to remove floating share buttons from.
  3. In the left sidebar Navigate to the Audience sub-menu and click Technology, then click Network.
  4. Underneath the graph you will see “Primary Dimension: Service Provider Hostname” click on “Hostname” to filter to hide service provider data.
  5. Copy down the valid hostnames to a separate document.
    • Valid hostnames are all places you would expect to see your tracking code. Pages of your website, Google Translated pages, and your shopping cart for example.
    • Invalid hostnames are things you don’t recognize, but can also be, or which are fronts spammers use to fool you. “(not set)” is also an invalid hostname that you can remove.
  6. Once you have your list of valid hostnames you will need to write an expression that combines all of them together into a “REGEX” or Regular Expression.
    • Google has some additional information on creating your Regular Expression that you may find helpful.
    • Here’s an example of a finished expression yours will likely be different though:|||||
    • You won’t need to include subdomains such as, or as those will be incorporated as long as your primary url “” is included.
  7. After you’ve completed your REGEX build we will need to incorporate it into a Hostname Filter.

Part 2: Add your Regular Expression to a Hostname Filter

  1. First you will want to create a new view for this data. Go to the Admin tab and select the drop down under the “View” section.
  2. Click “Create new view”
  3. Make sure the website button is selected and name your view “Ghost Spam Removed” select your timezone and click the “Create View” button.
  4. Make sure that your new view “Ghost Spam Removed” or whatever name you chose is selected in the drop down.
  5. Click the “Filters” button and then click “+ New Filter” to create a new filter.
  6. Name your Filter “Valid Hostnames Only” or something similar.
  7. Select Custom under the Filter Type.
  8. Choose the Include Radio Button
  9. Under the Select Field drop down choose “Hostname”
  10. Paste the Regular Expression “REGEX” you wrote in part 1 into the Filter Pattern Text Field.
  11. Click Verify this filter to see an example of what your filtered data will look like and check that you aren’t missing any important data you know should be there.
  12. Save your new filter and you’re done!

Part 3: Remember To Add New Valid Hostnames

Once you have your new Ghost Spam Filter set up, you’ll need to add in new valid hostnames as they appear over time to ensure accuracy. These might include traffic from places such as Youtube, or Paypal. You will need to add these new hostnames to your REGEX in your filter Ghost Spam Filter.

Now when your looking to see the filtered view all you have to do is go to admin and change your view to “Ghost Spam Removed.” All your reporting data should be filtered now, but you can always switch back to your all website data view when you want to.

Thanks for reading!

story written by Sam Jeanes