Home
Blog
Accurate Event Tracking with Multiple Pixels

November 28, 2017

Accurate Event Tracking with Multiple Pixels

Implementing a pixel is one of the cornerstones of Facebook Marketing to help you measure, optimize your ads and create the most relevant audiences for your business. Quite often, planning the optimal setup for your site may simply be getting the base pixel code on to your site and tagging key elements or critical parts of your funnel. But in some cases, you may legitimately need to have multiple pixels on the site to satisfy business realities.

Read on to learn about technical implications and solutions for managing multiple Facebook Pixels when setting up events.

Multiple Pixels

There are instances where multiple pixels could be a viable option to manage your marketing needs—especially when there are multiple stakeholders involved.

Imagine your large organization deals with one agency (Agency A) for performance marketing and another agency for branding activity (Agency B). Agency A and B have different processes to update their tags (for example, tag managers/containers and ownership) and plan all their activity separately.

In this scenario, what would be the best recommendation to consolidate these multiple codes to reduce the maintenance burden, ensure the most accurate tracking and minimize the possibility of technical errors?

Unexpected Behavior

The two following examples demonstrate instances where there may be unexpected behavior or extraneous pixel events firing. This firing could skew reporting and yield undesirable results when working with multiple codes.

Consider the scenario where Agency A wants to track a Purchase in Pixel A and Agency B wants to track a custom event (Step4) on Pixel B. They've installed two base codes on the same page to fire when it loads.

Example: Two Pixels in Two Base Codes

The following code is installed:

<script>
  ... base code truncated
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', '<PIXEL_A>');
  fbq('track', 'PageView');
  fbq('track', 'Purchase', {
                  'value': 4,
                  'currency': 'GBP'
  });
</script>

<script>
  ... base code truncated
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', '<PIXEL_B>');
  fbq('track', 'PageView');
  fbq('trackCustom', 'Step4'); //fires for both Pixel A and B
</script>

You expect Purchase events to be captured in Pixel A and Step4 to be captured in Pixel B; however, this isn't the case. The end result is summarized in the table:

*Even if there are two base pixel codes, the fbevents.js code only downloads or loads once.

Example: Two Pixel IDs in a Single Base Code

The following (modified) code is installed:

<script>
  ... base code truncated
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', '<PIXEL_A>');
  fbq('track', 'PageView');
  fbq('track', 'Purchase', {
                  'value': 4,
                  'currency': 'GBP'
  });

  fbq('init', '<PIXEL_B>');
  fbq('track', 'PageView');
  fbq('trackCustom', 'Step4'); //fires for both Pixel A and B
</script>

Nevertheless, the above code still yields the exact same overfiring behavior as above.

Why do the above snippets yield unexpected results?

When the init function is called against a pixel ID, it stores it in a global &quot;queue&quot;/structure where any subsequent call to track or trackCustom is fired for any pixel that was previously initialized.

In the previous example, this is why the Step4 custom event is fired for Pixel A, even when the trackCustom call is inserted after the init call for Pixel B. If unaware of this behavior, you may be firing extra events that may inadvertently affect reporting.

New Capabilities—trackSingle and trackSingleCustom

In early November 2017, two new capabilities (trackSingle and trackSingleCustom) were added to the pixel. These options enable you to selectively fire events for a specific pixel—even when multiple pixels are initialized on the page—without unexpected consequences.

For example, to fire the Purchase standard event only on Pixel A and Step4 custom event only on Pixel B, you can use the trackSingle or trackSingleCustom feature.

The following snippet selectively fires events on each pixel by specifying the specific Pixel ID and the events or parameters required:

<script>
  ... base code truncated
  'https://connect.facebook.net/en_US/fbevents.js');
  fbq('init', '<PIXEL_A>');
  fbq('init', '<PIXEL_B>');
  fbq('track', 'PageView'); //fire PageView for both initialized pixels

  // only fire the Purchase event for Pixel A
  fbq('trackSingle', '<PIXEL_A>', 'Purchase', {
        value: 4,
        currency: 'GBP',
  });

  // only fire the custom event Step4 for Pixel B
  fbq('trackSingleCustom', '<PIXEL_B>', 'Step4',{
    //optional parameters
  });

</script>

Takeaways

Understanding the behavioral differences among track, trackSingle or trackSingleCustom is important when there's a possibility of multiple pixels interacting on your page.

Using these new capabilities allows accurate tracking for multiple pixels and ensures there's no conflicting or unexpected behavior when events are defined to fire.


TAGS

Get our newsletter

Sign up for monthly updates from Meta for Developers.

Sign up