Twitter icon Instagram icon Pinterest icon Tumblr icon Snapchat icon Medium icon Facebook icon Linkedin icon Vine icon Reason SVG - Affordable Reason SVG - industry Reason SVG - scale Reason SVG - specialised Arrow scalable Illustration Specialised Illustration Affordable Illustration Flexible Illustration

What the hell is the Facebook pixel?

By Tom Gamon


If you know the enemy and know yourself, you need not fear the result of a hundred battles. If you know yourself but not the enemy, for every victory gained you will also suffer a defeat. If you know neither the enemy nor yourself, you will succumb in every battle.”

― Sun Tzu, The Art of War

If you are doing any amount of Facebook advertising, you will at some point run into the Facebook Pixel. You’ll either be trying to implement it on your own website, or speaking to your developers about how to get it set up. Whatever you are doing with it, it is 100% harder if you have no idea what it is or what it does — “know the enemy”. In this blog I will be attempting to explain basically how it works in a way that is understandable even if you don’t know the first thing about web development.

Let’s do this.

So, a quick overview. The Facebook pixel is a small piece of tracking code that you place on your website so you can monitor traffic arriving there and see if it’s coming from your Facebook advertising. You can also use it to create groups of people to target your advertising based on who has visited your website.

So far so good. But what actually IS the Facebook Pixel?

This. This is the Facebook Pixel.

<! — Facebook Pixel Code -->
<script>
!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’, ‘1234567891011’);
fbq(‘track’, ‘PageView’);
</script>
<noscript><img height=”1" width=”1" style=”display:none”
src=”https://www.facebook.com/tr?id=1234567891011&ev=PageView&noscript=1"
/></noscript>
<! — DO NOT MODIFY -->
<! — End Facebook Pixel Code -->

It is a small piece of Javascript (a programming language for the web) that sends information back to Facebook. The code above is what is known as the Facebook Pixel base code. It should sit on every page of your website, between the tags.

Looks pretty scary and intense right?

Luckily there are only two bits that you need to know or care about.

<! — Facebook Pixel Code -->
<script>
!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');
<strong>fbq(‘init’, ‘1234567891011’);
fbq(‘track’, ‘PageView’);</strong>
</script>
<noscript><img height=”1" width=”1" style=”display:none”
src=”https://www.facebook.com/tr?id=1234567891011&ev=PageView&noscript=1"
/></noscript>
<! — DO NOT MODIFY -->
<! — End Facebook Pixel Code -->

That seems a bit more manageable.

So what do they mean? Let’s do some translation.

<! — Facebook Pixel Code -->
<script>
!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');
<strong>Sup Facebook it’s ya homeboy Born Social here.
I’ve seen that this dude has had a look at this page on your website. Know him?</strong>
</script>
<noscript><img height=”1" width=”1" style=”display:none”
src=”https://www.facebook.com/tr?id=1234567891011&ev=PageView&noscript=1"
/></noscript>
<! — DO NOT MODIFY -->
<! — End Facebook Pixel Code -->

That doesn’t seem so intimidating any more. In our example, the string of numbers '1234567891011' is what tells Facebook that it’s Born Social here rather than someone else. This string of numbers is the Pixel ID, which you get when you set up your pixel. You should not reuse the same Pixel ID across multiple different websites, otherwise things will get confusing as you won’t know what information is coming from where.

Here is the whole ‘conversation’ between the Pixel and Facebook.

In a nutshell, that’s it. The Facebook Pixel is just a small piece of code that communicates back to Facebook telling it who is visiting your website and whether they have seen your advertising. It looks scary but when you break it down it’s pretty simple!

If you have any questions, or have any ideas for more blogs, then just grab me on Twitter.