Facebook

How To Block Spam Events From Your Facebook Pixel

Learn how to block spam events inflating data in your Facebook pixel by following this quick Google Tag Manager guide.

Brad Redding

Brad Redding is the Founder & CEO of Elevar. Specializing in analytics, tracking, GTM, and conversion optimization.

Over the past few years we’ve seen a growing # of brands end up with what we call “spam” events hitting their Facebook Pixel.

The symptom is typically this:

In Events Manager, you see some events that are not coming from your existing Facebook Pixel integration.

A common scenario is empty Purchase events coming through on product pages, home pages, or any other page besides your “thank you” page.

You will see these events in Recent Activities, and will often see the number of browser Purchase events be higher than server events and their total Shopify orders for the time frame.

These Purchase events typically have the same value for every event, don’t have an order ID, or have other characteristics that make them appear “fake”.

How To Block Spam Events via GTM:

If you’ve implemented your Facebook Pixel in your GTM web container, update the Facebook – Sitewide Pixel to the following (addition bolded):

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){
if(f.fbq)return;
n= f.fbq = function(){
  if (arguments[1] === "Purchase" && typeof arguments[2].order_id === "undefined") return;
  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>](<https://connect.facebook.net/en_US/fbevents.js>)');
fbq('init', '{{Facebook Pixel ID}}');
</script>
<!-- End Facebook Pixel Code -->

This will block Purchase events coming through without an order_id defined.

If you’re an Elevar customer, our pre-configured Purchase event includes an order_id by default.

fbpurchase

So we recommend that you double check this is in place and working for all checkouts before deploying.

How To Verify it Works

To test whether an event will be blocked, run the event code through the console and see if the hit comes through.

Example:

fbspamtest1

Since this event does contain an order_id, you will not see the Purchase hit sent to Facebook in the Network Panel:

fb network request

If you add an order_id to the event, you should see the hit come through:

purchase hit

If that works for you then you should be good to go!

Other Scenarios Spamming Facebook Pixels

Sometimes a pixel may be getting View Content or AddToCart spam events.

If this is the case then you can add additional checks in your base Facebook pixel code to the fix to block both types.

For example, maybe they are also getting AddToCart events without a value set.

In this scenario, you can use this revised version of block code (changes in bold):

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){
if(f.fbq)return;
n= f.fbq = function(){
  if (arguments[1] === "Purchase" && typeof arguments[2].order_id === "undefined") return;
  if (arguments[1] === "AddToCart" && typeof arguments[2].value === "undefined") return;
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>](<https://connect.facebook.net/en_US/fbevents.js>)');
fbq('init', '{{Facebook Pixel ID}}');
</script>
<!-- End Facebook Pixel Code -->

You can follow the same QA process as the Purchase event.

If you have a scenario other than these that you need a solution for and are not comfortable adjusting the logic, ask us for help!

And always always test before deploying to ensure you are seeing the events set up in GTM come through.

Props to our team – Katie and Thomas – for this great fix!

Leave a Reply

Your email address will not be published.

You may also like