StartupMobileMarketplaceMediaB2BRetailAny Industry

Retarget Customers with the Facebook Conversions API

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

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.  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 new Conversions API (formerly known as the “server-side pixel”, also known as the “CAPI”) introduces a new way to send events 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.)

This recipe provides a step-by-step guide on using Segment (an official Facebook Integration Partner) to collect your first-party data and sync it to Facebook for retargeting. 

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. 

Ecommerce events funnel

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

Retarget your Customers Facebook CAPI Hero Image

Step 1: Enable the Facebook Pixel destination onto your website

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

  1. Log in to 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)

    FB Pixel Destination Settings

  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:

Sample event payload for Facebook CAPI

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. Log in to Segment App.

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

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

  4. Enter your Pixel ID

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

  6. Enable the destination

    Facebook CAPI Destination Settings
  7. 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.

Getting started is easy

Start connecting your data with Segment.