Base Code
Before you can install the pixel, you will need your pixel’s base code, which you can find in the Ads Manager > Events Manager. If you have not created a pixel, follow these instructions to create one — all you will need is the pixel’s base code (step 1).
The base pixel code contains your pixel’s ID in two places and looks like this:
<!-- 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', '{your-pixel-id-goes-here}'); fbq('track', 'PageView'); </script> <noscript> <img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id={your-pixel-id-goes-here}&ev=PageView&noscript=1"/> </noscript> <!-- End Facebook Pixel Code -->
Placing the code within your <head>
tags reduces the chances of browsers or third-party code blocking the pixel’s execution. It also executes the code sooner, increasing the chance that your visitors are tracked before they leave your page.
Once you have added it to your website, load a page that has the pixel. This should call fbq('track', 'PageView')
, which will be tracked as a PageView
event in the Events Manager.
fbq('track', 'Lead');
Further examples and tracking types can be found in Facebook’s Documentation
Example Event:
This will regex any click events on tel: links
<script> jQuery('a[href*="tel:"]').on('click', function(){ fbq('track', 'Lead'); }); </script>
Specific Pixel Targeting (Multiple Facebook Pixels):
To target a specific pixel on a site using multiple Facebook pixels, you can specify the ‘trackSingle’ argument, and provide the pixel ID you wish to fire the event for:
fbq('trackSingle', '1234567898765432', 'InitiateCheckout');
It’s worth noting that a setTimeout or jQuery(‘document).ready(); initialisation may be required to wait for the pixel to load.
Example Event:
<script> setTimeout(function(){ fbq('trackSingle', '1672338979692086', 'InitiateCheckout'); },500); </script>