Growth & Marketing

Preparing for The Future of Advertising with Facebook Conversions API and Twilio Segment

Prepare for the world of first-party data with Facebook Conversions API and Segment.

Apr 28, 2021

By Andrew Jesien

What do iOS14, Google’s new privacy announcements, EU’s GDPR, and California’s CCPA all have in common? 

They introduce a new internet where:

  1. Consumer privacy comes first.

  2. Only first-party data survives.

  3. Browsers are less reliable tools to share data back to advertising platforms. 

Facebook’s answer to this new internet is the Conversions API (formerly known as the “server-side pixel”, also known as the “CAPI”). 

This article will explain what Facebook’s Conversions API is, why it’s worth focusing on now, and a step-by-step guide on using Segment (an official Facebook Integration Partner) to collect your first-party data and sync to Facebook for retargeting. 

What is the Facebook Conversions API? 

Currently, most businesses use the standard Facebook pixel to run ads. They do this by installing the Facebook pixel directly on their website or by using Segment to bundle and share pixel events automatically

With this setup, when users land on a website and complete actions (such as Product Viewed, Demo Requested, etc.), the pixel collects and sends these events to Facebook directly from the browser (user’s device).

While this is a powerful way to send first-party data to Facebook (and it’s not going anywhere soon), the introduction of new browser privacy policies, the death of third-party cookies, and the adoption of ad-blockers are making this type of tracking less reliable. Furthermore, iOS 14 changes will heavily limit how apps and websites on Apple devices can directly share conversion event information. 

Facebook’s Conversions API is a way to send your first-party data directly from your application servers (not the user’s device) to Facebook. 

This type of server-side communication is extremely reliable and allows you to choose exactly what data to share with Facebook, instead of only relying on data the Facebook pixel collects. Conversions API also allows you to share conversion events lower in the funnel that may not even take place on your website (e.g. within your app, CRM, Support Tool, etc.)

How can Segment help?

Segment allows companies to unify customer data collection to a single API, and then streams this data anywhere without requiring additional engineering effort. 

Instead of having your engineers build one-off integrations directly with the Facebook Conversions API (and every other tool), the idea is to track your events once to Segment, and then Segment can stream these events to your entire tech stack  - Analytics, Data Warehouse, CRM, Marketing tools, as well as the Conversions API.

For any data destination, Segment will perform all the data mappings and translations, so the data is being received by the partner destination properly. For example, with the Conversions API, Segment will do relevant data mappings and hash appropriate PII, as required by Facebook. 

Today there are two main use-cases to implement this Facebook CAPI destination via Segment:

  1. More Reliable Website Tracking: Use Segment to send web events using both the pixel and the Conversions API, where the server-side events are a backup for times the client-side Facebook pixel fails. For collecting website behavior, currently we still recommend loading Facebook’s standard pixel, and if you do this through Segment, Facebook will deduplicate when it receives the same events from both the pixel vs. Conversions API.

  2. New Additional Events: There may be key events that you only track server-side, or additional events that happen somewhere else lower in the funnel (e.g., In-app, CRM, Support, etc.). With Segment you can simply stream these server-side events over to Facebook.

In this article, we’ll teach you how to retarget anonymous users with Segment and Facebook’s Conversions API in three simple steps.

What do you need?

  1. Events already collected using Segment from both

    1. Client-side with Analytics.js, Segment’s website collection library

    2. Server-side with one of Segment’s server-side libraries

Example scenario

For example, let’s assume we’re tracking a standard eCommerce purchase funnel, and we want to make sure our lower-funnel events are extremely accurate (by tracking on both the client and the server). Depicted in the diagram below, we have the full purchase funnel tracked on the client (mapped to the Segment eCommerce Spec), whereas our more important lower-funnel events are also tracked server-side.  

(Note: This is just one example and not necessarily a recommendation. You may want to track the entire funnel server-side, or you may be sending in completely different events server-side, etc.)

For each event tracked, you’ll need to make a choice to share your event data with Facebook via one of three options - using the pixel, the CAPI, or both. This decision is up to you, but using a redundant set-up with both the pixel and Conversions API will be the most reliable and is the recommendation from Facebook. 

Optimize your Ad Spend with Facebook’s new Conversions API

To accomplish this, here’s a diagram of what we’re going to configure with Segment:

image (13)

Step 1: Enable the Facebook Pixel destination on your website

Follow instructions to enable the standard Facebook Pixel Destination from your client-side Segment source. 

  1. Log in to the Segment App.

  2. Click Add Destination and find the Facebook Pixel Destination.

  3. Choose your Segment source that is collecting client-side website events.

  4. Enter your Pixel ID.

  5. Complete any relevant category or event mappings (see docs for details).

  6. Enable the Use UserId or Anonymous Id as External Id setting, which will make sure events sent to facebook include an External ID that matches the Segment userId (or anonymousId if there is no userId). This will be important for Facebook deduplication (more details at bottom)

    Optimize your Ad Spend with Facebook’s new Conversions API

  7. Enable the Destination.

  8. Once enabled, the following will happen automatically:

    1. Segment will bundle the Facebook pixel SDK onto the browser (aka device-mode).

    2. Facebook pixel SDK will set two first-party cookies - the fbp and fbc

    3. Segment will automatically translate tracked events and send them to Facebook from the browser (user’s device).

Step 2: Share identifiers from client to server, add to server-side events

This step will require engineering effort, and really depends on the technologies that you use. For retargeting anonymous users, the key fields you’ll want to pass from the browser to your application servers are the following (see Facebook documentation on retargeting):

You’ll then add these identifiers to each server-side event you want to share with Facebook. You’ll also want to choose the appropriate action_source, depending on where this event occurred. For example, if the event occurred on your website, you’ll want to specify an action_source of website and also include the website url in the field. More instructions in our Facebook Conversions API documentation

As an example, below is a Product Added event sent server-side to Segment. Notice the ip, userAgent, and url are in the context object, whereas the action_source, fbc, and fbp are in the properties object:

Optimize your Ad Spend with Facebook’s new Conversions API

Note: The example above is for an anonymous shopper, however, you should include the known identifiers Facebook supports when possible. For example, if this were Order Completed, this event would likely also include an email and userId property. 

Step 3: Enable the Facebook Conversions API for server-side events

Now we just need to turn on the Facebook Conversions API destination for this server-side source configured in Step 2. 

  1. Login to Segment.

  2. Click Add Destination and find the Facebook Conversions API destination

  3. Choose the Server-Side source of data configured in Step 2.

  4. Authorize Segment as a partner integration from your Facebook Business Event Manager Pixel Settings.

  5. Enter your Pixel ID

  6. Complete any relevant category or event mappings in the settings.

  7. Enable the destination.

    Optimize your Ad Spend with Facebook’s new Conversions API

  8. Log into Facebook Event Manager and confirm that duplicate events between the Pixel and CAPI are being merged. 

A quick note on deduplication logic...

For situations where you’re firing events using both the pixel and Conversions API, Facebook is able to deduplicate events using two properties that Segment sends to Facebook — the Event Name and External ID. For this reason, you’ll want to make sure your event mappings match between these two destinations, and that they are both configured to send the same External ID. This recipe configures Segment to set the External ID to the userId  (or anonymousId when user is not authenticated). 

Also, for Facebook to successfully deduplicate events, you’ll want to make sure you’re triggering client-side events before triggering the same events server-side. Facebook only dedupes when events are received in this order. 

Wrapping up

Here’s what we’ve done in this recipe:

  • Configured the standard Facebook pixel to load onto your website and collect events

  • Shared device-info from the browser to your app servers, and sent enriched events into Segment server-side. 

  • Configured server-side events to stream to the new Facebook Conversions API, to provide a more accurate and complete view of your conversion funnels for your customer base. 

The State of Personalization 2023

Our annual look at how attitudes, preferences, and experiences with personalization have evolved over the past year.

Get the report
SOP 2023

The State of Personalization 2023

Our annual look at how attitudes, preferences, and experiences with personalization have evolved over the past year.

Get the report
SOP 2023

Share article

Want to keep updated on Segment launches, events, and updates?

We’ll share a copy of this guide and send you content and updates about Twilio Segment’s products as we continue to build the world’s leading CDP. We use your information according to our privacy policy. You can update your preferences at any time.