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.
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.
To accomplish this, here’s a diagram of what we’re going to configure with Segment:
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.
Log in to Segment App.
Click Add Destination and find the Facebook Pixel Destination
Choose your Segment source that is collecting client-side website events.
Enter your Pixel ID
Complete any relevant category or event mappings (see docs for details).
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
anonymousIdif there is no
userId). This will be important for Facebook deduplication (more details at bottom)
Enable the Destination
Once enabled, the following will happen automatically:
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):
The two first-party cookies set by Facebook Pixel -
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
website and also include the website URL in the
context.page.url 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
url are in the context object, whereas the
fbp are in the properties object:
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
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.
Log in to Segment App.
Click Add Destination and find the Facebook Conversions API destination
Choose the Server-Side source of data configured in Step 2.
Enter your Pixel ID
Complete any relevant category or event mappings in the settings.
Enable the destination
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
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.
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.