Stape

How to Filter Google Analytics Spam With the Help of Google Tag Manager Server-Side Tagging

Updated
Oct 24, 2022
Published
Nov 22, 2020

What if you are faced with spam in Google Analytics reports? Does it mean that someone can access your Google Analytics accounts? Or maybe someone can modify data inside your GA? How can you prevent it? 

There are two main types of Measurement Protocol spam: referral traffic and events spam. More rarely you can see spam in languages, keywords, URLs, transactions, and so on. In this article, I will explain what Measurement Protocol spam is and how you can prevent it with the help of Google Tag Manager Server-Side tagging.

Why would someone send spam into Google Analytics?Copy link to this section

Google Analytics is the most popular web analytics tool used by millions of users. Referral spammers hope that when you go to Google Analytics and see traffic from unknown websites, you will be curious to see what they are. It is one of the grey ways of getting traffic. There are multiple ways of monetization: redirecting to any affiliate offers or directing to a landing page offering to buy something, download software, promote a marketing agency, or any other service. A few years ago, it was even used in politics. Before the Trump election, many GA accounts were hit by referral spam that was saying “Vote for Trump”.

To send fake hits to your GA account spammers need to know your Google Analytics ID. But sometimes they don’t even bother themselves with finding real Google Analytics IDs. Spammers may generate fake IDs in large quantities and hope that some of them are real GA identifiers. An automated script sends false data to GA accounts using measurement protocol. 

universal analytics stopped working

How can referral spam affect your website?Copy link to this section

Because of ghost spam, you cannot see the real data about your website visitors since fake traffic is mixed with organic. It affects all GA metrics: number of visits, bounce rate, avg. session duration, etc. 

It can also lower your position in the organic ranking since search engines can interpret spam traffic as attempts of increasing your SEO positions by using grey technologies. 

How can you block referral spam with the help of Google Tag Manager Server Tagging?Copy link to this section

There are two ways of blocking referral spam through the GTM server container. GTM server-side tagging can be used not only for blocking Measurement Protocol spam, but it can also help to reduce the loading time of your website, better protect your customer data, have access to full data inside analytics software, etc. This article explains the main benefit of the GTM server container. You can test GTM server-side tagging for free using our service. In our blog, you can also find several useful articles that describe what possibilities you’ll have if you move from web container to server. 

1. Hiding your real Google Analytics ID. 

Some of the spammers first crawl websites (similar to what google bots do) and scrape Google Analytics IDs. After that, they use a Measurement Protocol to send fake hits to your Google Analytics. If you’ve set up a GTM server container and added a custom tagging URL (you can check how to set up a GTM server container in this article), it is possible to replace your real Google Analytics ID with the fake one. Spambots will see the fake Google Analytics ID and won’t be able to send Measurement Protocol spam into your real Google Analytics account. Your GA settings will look similar to the settings on the screenshot. You can add any Tracking ID you want, but make sure you added and set up the transport URL. I recommend testing these changes before publishing them. To do that, just log in to GA and test data in the realtime.

variable configuration
test data in ga

2. Adding a secret code to your Google Analytics 

The first method won’t help you prevent spam traffic from those who send requests to random Google Analytics IDs. Sine, in this case, spammers don’t need to know your Google Analytics ID. It’s just a matter of luck if your GA account will be on their list. This type of spam relies on quantity, not quality. 

You can prevent this type of spam by adding a secret key. Google Analytics tag inside your server container should send this key. You will have to add this secret key as a custom dimension and then create a filter that allows traffic that matches custom dimensions. 

The first step is to add a new custom dimension inside your Universal Analytics tag in the server container. 

tag configuration

Then, add a new custom dimension in GA and create a filter that will include only traffic with this secret key.

add filter to view

Chances are that random spammers will know your secret key is close to zero. So this way, you can keep your Google Analytics data clean.

If you want to filter referral spam inside GA4, the second method that I described in this article won’t work since filters are not available inside GA4. But the good news is that Google uses a default feature to help prevent measurement protocol spam. This feature is called Measurement Protocol API secrets. It allows you to create a secret value to enable additional events to be sent into this stream through the Measurement Protocol. 

measurement protocol 

This is one of the many possibilities that GTM server-side tagging can offer you. For instance, we also described how you can use it to send Slack notifications in this article.

Would like to get help with filtering Google Analytics spam?

Just tell us where you feel stuck. Click Need assistance, fill up the form, and we will send you a quote.

Need assistance
Tagged with:Google Analytics

Relevant posts

Updated Oct 24, 2022

3 Easy Steps to Test Server-Side Universal Analytics/GA4 and Facebook Conversion API

Google released a Server-Side version of Google Tag Manager in 2020. Server-side tracking is more complicated than the web container set up, at least for now, since the idea and technology behind server tagging are entirely different from what we used to have on the web. But server-side tagging will give your site huge benefits. Server-side tagging is getting more popular due to its ability to track people using AdBlockers, browsers with ITPs, and other tracking restrictions. The purpose of this article is not to convince you to start using server-side tagging (there is another blog post that describes the main benefits of server-side tracking). I assume that you’ve already decided to implement server-side tagging on your site. This blog post will show you how to check whether Server-Side tracking for Universal Analytics, GA4, and Facebook conversion API was set up correctly.

Updated Feb 23, 2024

Google tag manager server-side: How to set up server Tag Manager, Universal Analytics, GA4, and Facebook conversion API

Server-side tagging has been one of the main trends in web analytics for the last couple of years. Ad blockers, Intelligent Tracking Protection, 3rd party cookie restrictions, regulations like GDPR made analytics and advertising companies start worrying about how and what information they collect about site visitors. Server-side tagging allows moving third-party tags off your site and into a cloud server. In this case, third-party pixels are loaded directly from the could server rather than your site. In this article, I will explain and demonstrate the basics of setting up Google Tag Manager server container, server Universal Analytics, GA4, and Facebook Conversion API.

Updated Feb 5, 2022

Facebook Tag for Google Tag Manager Server Side

Using Facebook Conversions API, you can send events to Facebook Event Manager. That is the perfect alternative to Facebook SDK because Conversions API speeds up page loading and helps track users more accurately. We created a Facebook tag for the GTM Server-Side container that uses Facebook Conversions API to track events.

Host your GTM server at Stape