Facebook Pixel Web Device Mode Integration
10 minute read
After you have successfully instrumented Facebook Pixel as a destination in RudderStack, follow this guide to correctly send your events to Facebook Pixel in device mode.
Find the open source JavaScript SDK code for this destination in the GitHub repository.
Important: Consent management and privacy compliance
Facebook Pixel uses the
fbclidparameter to identify users on the Facebook platform. This identifier can be considered personal information under privacy laws like CIPA (California Information Privacy Act). Therefore, you must implement proper consent management before enabling Facebook Pixel tracking to ensure compliance with applicable privacy regulations.See the following resources for more information on using RudderStack’s consent management feature:
Page
When you make the page call, RudderStack sends the data to Facebook Pixel with the event type as pageView. You can also pass properties to page - RudderStack automatically sends these properties along with the event ID to Pixel.
A sample page call is as shown:
rudderanalytics.page()Track
The track call lets you track custom events as they occur in your web application.
A sample call looks like the following code snippet:
rudderanalytics.track("Product Added", {
order_ID: "123",
category: "boots",
product_name: "yellow_cowboy_boots",
price: 99.95,
currency: "EUR",
revenue: 2000,
value: 3000,
checkinDate: "Thu Mar 24 2018 17:46:45 GMT+0000 (UTC)",
})In addition to the above call, a contentType in the integrations options can be available. If present, it will precede the default value or dashboard settings of contentType.
rudderanalytics.track(
"Product Added",
{
order_ID: "123",
category: "boots",
product_name: "yellow_cowboy_boots",
price: 99.95,
currency: "EUR",
revenue: 2000,
value: 3000,
checkinDate: "Thu Mar 24 2018 17:46:45 GMT+0000 (UTC)",
},
{
"Facebook Pixel": { contentType: "mycustomtype" },
}
)String is the only valid data type for thecategoryfield. However, you can pass an array of string values which will be concatenated using a delimiter (,) before sending the events.
Standard events
This destination does not strictly adhere to the RudderStack Ecommerce Event Spec.
RudderStack maps the event name in the payload to the Facebook standard event before sending it to Facebook Pixel. The properties are sent as the standard events require them. Refer to the Ecommerce Events Specification for more information.
RudderStack maps the following events to the Facebook standard events by default:
| RudderStack Event | Facebook Standard Event |
|---|---|
Product List Viewed | ViewContent |
Product Viewed | ViewContent |
Product Added | AddToCart |
Order Completed | Purchase |
Products Searched | Search |
Checkout Started | InitiateCheckout |
Click here to see the full list of supported Facebook standard events
AddToCartAddToWishlistAddPaymentInfoLeadCompleteRegistrationContactCustomizeProductDonateFindLocationInitiateCheckoutPurchaseScheduleSearchStartTrialSubmitApplicationSubscribeViewContent
You can use the RudderStack to Facebook event mappings dashboard setting to override the default mappings specified in the table above.
Note that:
For the
Purchasestandard event,properties.revenueis a required field.For the
Products Searchedevent, thequeryproperty must be a string.If you map an event with the
ViewContentstandard event using the RudderStack dashboard setting and don’t send theproductsarray in themessage.propertiesobject:javascript"properties": { "phone": 1-202-555-0146, "email": "alex@example.com", "category": "clothing", "list_id": "1234", "testDimension": true, "testMetric": true }Then,
content_idsis mapped toproperties.categoryvalue (clothingin this case) andquantityis set to1inside thecontentsobject.
The below table elaborates the property mappings between RudderStack and Facebook corresponding to the RudderStack event:
| RudderStack event | RudderStack property | Facebook property |
|---|---|---|
| Product List Viewed | ||
products.$.product_idproducts.$.skuproducts.$.id | content_ids | |
categorycontentNamecurrencyvalue | content_categorycontent_namecurrencyvalue | |
products.$.product_idproducts.$.skuproducts.$.idproducts.$.quantityquantityproducts.$.priceprice | contents.idcontents.quantitycontents.item_price | |
| Product Viewed | ||
product_idskuidproduct_namenamecategorycurrency | content_idscontent_namecontent_categorycurrency | |
product_idskuidquantityprice | contents.idcontents.quantitycontents.item_price | |
| Product Added | ||
product_idskuidproduct_namenamecurrency | content_idscontent_namecurrency | |
product_idskuidquantityprice | contents.idcontents.quantitycontents.item_price | |
| Order Completed | ||
products.$.product_idproducts.$.skuproducts.$.id | content_ids | |
contentNamecurrencyrevenue | content_namecurrencyvalue | |
products.$.delivery_categoryproperties.delivery_categoryproducts.$.product_idproducts.$.skuproducts.$.idproducts.$.quantityquantityproducts.$.priceprice | contents.delivery_categorycontents.idcontents.quantitycontents.item_price | |
| Products Searched | queryproduct_idskuidcategorycurrencyvalue | search_stringcontent_idscontent_categorycurrencyvalue |
product_idskuidquantityprice | contents.idcontents.quantitycontents.item_price | |
| Checkout Started | ||
products.$.product_idproducts.$.skuproducts.$.id | content_ids | |
categorycurrencyrevenue | content_categorycurrencyvalue | |
products.$.product_idproducts.$.skuproducts.$.idproducts.$.quantityquantityproducts.$.priceprice | contents.idcontents.quantitycontents.item_price |
In the above table, the default values for the
currencyandquantityproperties areUSDand1respectively.Fallback behavior: When both
products[].priceand top-levelpriceare present,products[].pricetakes mapping precedence for Facebook’scontents.item_pricefield.
Other standard events
If you map your event to any of the following Facebook standard events, then RudderStack treats it as a standard event as well:
AddToWishlistAddPaymentInfoLeadCompleteRegistrationContactCustomizeProductDonateFindLocationScheduleStartTrialSubmitApplicationSubscribe
Legacy events
You can map events to the legacy conversion Pixel IDs in the RudderStack dashboard. The events specified in the mapping are sent to Facebook with the mapped Pixel ID.
Note that the conversion events only support currency and value as their event properties.
Custom events and properties
RudderStack supports sending custom events and properties to Facebook — it automatically flattens all properties from your event into Facebook’s custom_data field.
Custom events
You can use custom events to send an event that does not appear in any of the mappings.
A sample custom event is shown below:
rudderanalytics.track("Video Watched", {
// All properties become custom_data
video_title: "Product Demo",
video_duration: 120,
completion_rate: 0.85,
user_engagement: "high"
})How custom properties work
- Automatic processing: All properties in the
propertiesobject are included in Facebook’scustom_datafield. - Property flattening: RudderStack flattens the properties to match Facebook’s API format.
- Reserved exclusions: Certain properties (
opt_out,event_id,action_source) are excluded from custom data. - Special arrays: Properties like
content_idsandcontentsare preserved as arrays.
Standard event with custom properties
RudderStack also supports sending standard Facebook events along with custom properties. An example is shown below:
rudderanalytics.track("Purchase", {
// Standard ecommerce properties
revenue: 150.00,
currency: "USD",
products: [
{
product_id: "PROD_123",
price: 75.00,
quantity: 2,
category: "electronics"
}
],
// Custom properties (sent as custom_data to Facebook)
customer_segment: "premium",
campaign_id: "summer_sale_2024",
store_location: "downtown",
payment_method: "credit_card",
discount_applied: 10.00,
loyalty_points_earned: 150
})Custom properties are automatically processed and sent to Facebook Pixel. No additional configuration is required beyond setting up your PII handling preferences in the RudderStack dashboard.
PII handling
The Facebook Pixel integration handles Personally Identifiable Information (PII) based on your dashboard configuration to ensure compliance with privacy regulations.
Make sure your PII handling configuration complies with applicable privacy laws and Facebook’s data policies.
Click here to see the complete list of PII properties that RudderStack denylists by default.
emailfirstNamelastNamefirstnamelastnamefirst_namelast_namegendercitycountryphonestatezippostalCodebirthday
How PII handling works
Detection: Properties are checked against the default PII list and your custom denylist.
Processing: PII properties are either:
- Excluded from the event payload entirely
- Hashed using SHA-256
- Included if allowlisted
Deduplication
Facebook Pixel lets you send events via your web browser and server by leveraging the Conversion API.
Depending on how you send your events with this dual set-up, redundant events may be received by Facebook. Therefore, Facebook tries to deduplicate events coming in to help get accurate representation of your data.
event_id method (Recommended)
Facebook’s recommended deduplication strategy is to leverage the event_name and event_id properties. Multiple events coming into Facebook are deduplicated if they meet the following criteria:
- They are sent within 48 hours of each other
- They are received by the same Facebook Pixel ID
- They have the same
event_name, for example,Purchase - They have the same
event_id
Note that:
- The
event_idmust be unique to that specific event and the same for both events coming from the Pixel and Conversion API. For example, theevent_idcould be the purchase order number.- You can set the
event_idintraits,context.traitsorpropertiesobject as a unique identifier.- If you don’t set the
event_id, RudderStack usesmessageIdto map to Facebook’seventId.
The event_name will be picked up from the name of the event. For more information on the logic behind the event_id deduplication, see the Facebook documentation.
fbp and external_id method (Not Recommended)
For this approach, it is necessary to first send an event from the browser, then from the server. Both events must have the same event_name, and the same fbp parameter and the same external_id.
If the browser event is received before the server event and both events have the sameevent_name,fbp, andexternal_id, then the server event is discarded.
A few shortcomings of this deduplication method are listed below:
- This method only works for deduplicating events sent first from the browser and then the server.
- It will always discard the server event if Facebook identifies a redundant event.
- There will be no deduplication if two consecutive browser events with the same information are sent to Facebook. The same is true if two server events with the same information are sent to Facebook.
RudderStack maps the event_name from the name of the sent event. The fbp parameter is taken from the context.fbp key-value pair. Finally, the external_id will just be the userId or anonymousId (if userId is not present).
For more information on the logic behind the fbp and external_id deduplication, see the Facebook documentation.
Timestamps
The Facebook Pixel integration uses two timestamp formats:
1. Event timestamps (event_time)
- Format: Unix timestamp (in seconds)
- Purpose: Event occurrence time
- Example:
1597383030 - Validation: Must be within 7 days of occurrence (62 days for physical store events)
2. Travel/accommodation date fields
Format: ISO 8601 without timezone
Purpose: Specific date/time for travel and accommodation events
Examples:
- Date only:
2025-10-09 - Date and time:
2025-10-09T14:30:00
- Date only:
Supported fields:
checkinDate,checkoutDate,departingArrivalDate,departingDepartureDate,returningArrivalDate,returningDepartureDate,travelEnd,travelStart
Automatic timestamp conversion
RudderStack converts ISO 8601 timestamps to Unix seconds for event_time, as described below. This setup ensures accurate event tracking and compatibility with Facebook’s Conversions API.
Timezone handling
- Event Time: Converted to UTC Unix timestamp
- Travel Dates: ISO 8601 without timezone (treated as UTC)
- Validation: Events must be within 7 days of occurrence
Best practices
- Send timestamps in ISO 8601 format. RudderStack converts them to Unix seconds.
- Use date-only for travel fields when time is not needed.
- Ensure timestamps are within Facebook’s time window.
- Use UTC to avoid timezone issues.
Error handling
- Invalid timestamps are rejected.
- Events older than 7 days (62 days for physical store) are rejected.
- Future events beyond 1 minute are rejected.
Send custom content_type field
You can send a custom content_type field by specifying it in the properties.content_type field of your event.
RudderStack sets the value of content_type in the following priority order:
- It gives the highest priority to
properties.content_typein your event. - If
properties.content_typeis absent, RudderStack sets thecontent_typetoproductby default, except in the following cases:
Case 1: If Product List Viewed event is sent
| Scenario | Outcome |
|---|---|
Event sent with products array | content_type is set to product |
Event sent without products array | content_type is set to product_group |
Case 2: If Product Viewed event is sent but not mapped in the RudderStack dashboard
| Scenario | Outcome |
|---|---|
Event sent with products array | content_type is set to product |
Event sent without products array | content_type is set to product_group |
Case 3: If you send any other event mapped to the View Content standard event in the RudderStack dashboard
| Scenario | Outcome |
|---|---|
Event sent with products array | content_type is set to product |
Event sent without products array | content_type is set to product_group |
Thecontent_typeparameter accepts only two values —productandproduct_group.
Validation and error handling
The Facebook Pixel integration validates events and may reject them for the following reasons:
Event validation errors
| Error | Resolution |
|---|---|
| Invalid event duration | Events must not be older than 7 days (62 days for physical store), or more than 1 minute in the future |
| Invalid product array | products must be an array of objects |
| Invalid query type | Search queries must be string, number, or boolean |
| Invalid revenue | Revenue must be convertible to a number |
| Missing required fields | Standard events must not miss required properties |