Facebook Pixel and Cookie Preferences article and the related new updates allow us to dive into details about Facebook Pixel and the events it can track (mostly standard events).
I’ll proceed through the steps in the article generally under the assumptions of advertising and analysis, and that both first- and third-party cookies are active.
You can find support requests related to Tag Management here.
Facebook Pixel and Advanced Matching
Through the Facebook Ad Manager (Facebook Ad Manager), we selected the option to manually upload the code, which includes our Facebook Pixel—specifically, the static code (base code) and the snippet containing our standard event (standard event). By default, the event sent to us is PageView, represented as fbq('track', "PageView"). The snippet provided to us is approximately as follows;
<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', '[Facebook-pixel-ID]');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id='[Facebook-pixel-ID]&ev=PageView&noscript=1" /></noscript>
With this code1:
- Understand how cross-device ad conversions are affected,
- Be certain that your ads reach users who are likely to take action,
- Automatically show users the products or similar products they viewed during their visit to your website, especially when they are browsing dynamic ads,
- Gain rich analytics on how visitors use your website.
Of course, we don’t have to manually upload the pixel. Instead, we can use the option Use an integration or tag manager, and evaluate the available options across platforms such as Google Tag Manager, Magento, PrestaShop, Segment, WooCommerce, WordPress, and others.
When implementing through partners, in addition to manual code, the agent parameter will be added to the relevant pixel snippet. The following line defines Google Tag Manager:
fbq('set','agent','tmgoogletagmanager', '[Facebook-pixel-ID]');
By carrying out the installation process in collaboration with e-commerce, website platform, and/or tag management solutions, you will be able to automatically utilize many standard events2. This enables you to reach your products and services with greater accuracy to specific audiences, boost your sales, and measure the performance of your campaigns more effectively. Additionally, when logging in, logging out, or signing up, the system will capture customer data (e.g., email addresses) from your website, enabling the automatic advanced matching feature of Facebook Pixel to correctly associate conversions. Facebook notes that, after capturing these data, it encrypts them for security reasons. After encryption, the data is used to more accurately match website visitors with Facebook users, resulting in more closely aligned conversion events and the creation of larger, more targeted audience segments for Facebook campaigns.
The automatic advanced matching feature can be managed under Event Manager. Under the Use Automatic Advanced Matching option, you can view the automatically captured data fields (email > em, first name > fm, last name > ln, date of birth > db, gender > ge, city > ct, postal code > zp, and country > st). You can also include these relevant data fields into the Facebook Pixel static code field as follows.
fbq('init', '[Facebook-pixel-ID]', {
'em': '[email-address]',
'fn': '[first-name]',
'ln': '[last-name]',
'ph': '[phone-number]',
'ge': '[gender]',
'db': '[date-of-birth]',
'ct': '[city]',
'st': '[region-country]',
'zp': '[postal-code]'
});
In reverse, you can also disable the automatic advanced matching feature within the corresponding Facebook pixel’s hardcoded code area. To do so, you need to add the following line:
fbq('set', 'autoConfig', false, '[Facebook-pixel-ID]');
Facebook Pixel and Special Cases
Before discussing standard events, I’d like to mention two special cases. The first one is the image row present in the standard code, and the second one is how you can use multiple Facebook pixel IDs…
NoScript and IMG Tag (Image Only Pixel Code)
The Facebook Pixel includes an image tag to handle situations where JavaScript is not executed.
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=[Facebook-pixel-ID]&ev=PageView&noscript=1" /></noscript>
Thanks to this automatically added line, the PageView event acts as a complementary element for scenarios where the standard code fails to process. So, can we further enhance this img tag for such situations? Absolutely! Just as with the PageView event, you can use the img tag for many other events as well3. For example, let’s create an img tag for the ViewContent event.
<noscript><img src="https://www.facebook.com/tr?id=[Facebook-pixel-ID]&ev=ViewContent&cd[content_name]=ABC%20Leather%20Sandal&cd[content_category]=Shoes&cd[content_type]=product&cd[content_ids]=1234&cd[value]=0.50&cd[currency]=USD&noscript=1" height="1" width="1" style="display:none" /></noscript>
As you can see, we can pass many values such as [content_name], [content_category], [content_type], [content_ids], [value], and [currency] to the Ad Manager via this tag. If we wanted to pass these values inside the fbq function through the img tag, our code would look like this:
fbq('track', 'ViewContent', {
content_type: 'product',
content_ids: ['1234'],
content_name: 'ABC Leather Sandal',
content_category: 'Shoes'
value: 0.50,
currency: 'USD'
});
I’ll also provide further details about these parameters under the Standard Events section. Additionally, let’s demonstrate our last example using a custom pixel.
fbq('trackSingleCustom', '[Facebook-pixel-ID]', 'PageView');
The img tag (img pixel) that will be generated for trackSingleCustom will look like this:
<noscript><img src="https://www.facebook.com/tr?id=[Facebook-pixel-ID]&ev=CustomEventName&cd[custom_param1]=ABC&cd[custom_param2]=123&cd[value]=10.00&cd[currency]=USD&noscript=1" height="1" width="1" style="display:none" /></noscript>
For now, seeing how these parameters are handled within the img tag is sufficient. This approach remains valid when using different Facebook pixel IDs. Let’s now move on to another scenario.
Working with Different Facebook Pixels (MultiPixel and Pixel Sharing)
Yes, we can work with different pixels for different purposes. For example, different agencies might be running different advertisements, or we might want to track specific sales on a particular marketplace. In such cases, with a few additional adjustments, we can successfully define and track multiple pixels and events. Moreover, we can designate certain events as shared across pixels, while making others valid only for specific pixels.
<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', '[Facebook-pixel-ID-1]');
fbq('init', '[Facebook-pixel-ID-2]');
fbq('track', 'PageView');
</script>
<noscript>
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id='[Facebook-pixel-ID-1]&ev=PageView&noscript=1" />
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id='[Facebook-pixel-ID-2]&ev=PageView&noscript=1" />
</noscript>
The above Facebook Pixel code defines two pixel ID values: [Facebook-pixel-ID-1] and [Facebook-pixel-ID-2], both of which can process the standard PageView event. Similarly, for the image pixel, both IDs are defined. In addition to the modifications to the <img> tag under the NoScript and IMG Tag (Image Only Pixel Code) section, you can associate events with different pixel ID values by simply specifying the relevant ID values within the <img> tag. You can use the trackSingle parameter4.
fbq('init', '[Facebook-pixel-ID-1]');
fbq('init', '[Facebook-pixel-ID-2]');
fbq('track', 'PageView');
fbq('trackSingleCustom', '[Facebook-pixel-ID-1]', 'Step4');
fbq('trackSingle', '[Facebook-pixel-ID-2]', 'ViewContent', {
content_type: 'product',
content_ids: ['1234'],
content_name: 'ABC Leather Sandal',
content_category: 'Shoes',
value: 0.50,
currency: 'USD'
});
Within the above definitions, the common standard event for both [Facebook-pixel-ID-1] and [Facebook-pixel-ID-2] is PageView; however, the defined trackSingleCustom event for Step4 applies only to [Facebook-pixel-ID-1], while ViewContent applies only to [Facebook-pixel-ID-2].