How to Remove Spam Referral Traffic from Facebook

Let's start

So recently I noticed that installing Facebook Pixel via Google Tag Manager records spam traffic in ads manager. I didn’t notice this until I saw the purchase pixel. It was displaying 24 purchases in the last 7 days but there was no actual purchase in the backend.

How to view the referral URL in ads manager?

To make sure your pixel data is accurate and there is no spam referral, open your ads manager and navigate to pixels. Select the active pixel. Scroll down to see the graph and click on activity from the graph navigation menu.

 fb pixel activity analysis

In the activity tab, click any event or pageview pixel. I clicked on the add to cart pixel to see the referral URL.

 check referral url

If you look at the referral URL, it is not the website URL, instead, it belongs to GTM. The referral URL is gtm-msr.appspot.com

This is really annoying and I believe you have never looked at this data until you check the purchase pixel. Because we can imagine that ok, people are visiting my website and they perform certain activities.

How to block appspot referral in GTM?

Now, how do we actually solve this issue? There is not a big thing to do, you only have to add a javascript code which will prevent the pixel code to fire when the referral equals to the appspot URL.

You will have to add the below line of code to every pixel(base + event) you have added via GTM.

if((document.location.href.search(‘appspot.com‘)==-1)&&(document.referrer.search(‘appspot.com‘)==-1)){

pixel code here

}

Below is an example of how base and event pixel will be modified.

Base Pixel:

<script>
  if((document.location.href.search('appspot.com')==-1)&&(document.referrer.search('appspot.com')==-1)){

!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', xxxxxxxxxxxxxxx); // Insert your pixel ID here.
fbq('track', 'PageView');
  }
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxxxx&ev=PageView&noscript=1"
/></noscript>

Event code:

<script>
if((document.location.href.search('appspot.com')==-1)&&(document.referrer.search('appspot.com')==-1)){
  
    fbq('track','ViewContent',{
        content_type: 'product',
        content_ids:skuId,
        content_name:title,
        content_category:categories,
        value:price,
        currency: 'Rand'
    });
}
</script>

Once you add this to all pixels, you will never have to see any referral traffic in ads manager and your data will be accurate. If you have questions regarding this topic, please ask us directly on Twitter.

Don't miss out when new resources launch

Our customer analytics experts share wisdom only once a month

Share now
We are customer-analytics consultancy that transforms messy data into actionable insights that will help you grow your company and make better data-backed decisions.