Facebook Pixel Events, Tracking Events, and JSON
- Facebook Pixel Events & JSON parameters
- Facebook Tracking Events
- Required Facebook Pixel Events
Tracking Events + JSON
All standard events are tracked by calling the pixel’s fbq('track')
function, with the event name, and (optionally) a JSON object as its parameters. For example, here’s a function call to track when a visitor has completed a purchase event, with currency and value included as a parameter:
fbq('track', 'Purchase', {currency: "USD", value: 30.00});
Below is the JSON portion of the above code:
{currency: "USD", value: 30.00}
You can call the fbq('track')
function anywhere between your web page’s opening and closing <body>
tags, either when the page loads, or when a visitor completes an action, such as clicking a button.
JSON Parameters
Parameters are optional, JSON-formatted objects that you can include when tracking standard and custom events.
To include a parameter object with a standard or custom event, format your parameter data as an object using JSON, then include it as the third function parameter when calling the fbq('track')
or fbq('trackCustom')
functions:
fbq('track', 'Purchase', // begin parameter object data { value: 115.00, currency: 'USD', contents: [ { id: '301', quantity: 1 }], content_type: 'product' } // end parameter object data );
JSON Object Properties
You can include predefined JSON object properties with any custom events and any standard events that support them.
Some examples:
content_category
content_ids
content_name
content_type
delivery_category
Full list at source, under Object Properties section.
fbq('track', 'Purchase', // begin parameter object data { value: 115.00, currency: 'USD', contents: [ { id: '301', quantity: 1 }], content_type: 'product', delivery_category: 'in_store' } // end parameter object data );
Source: Facebook Conversion Tracking
Reference (Standard Events & JSON)
Full reference list of Standard Events and JSON object properties
You can use the fbq('track')
function to track the following standard events. Standard events also support parameter objects with specific object properties.
Required Facebook Pixel Events and Parameters for Dynamic Ads
To run dynamic ads for products, your pixel must include the following Standard Events:
Event name | Description |
---|---|
ViewContent | Someone viewed an item in your catalog. |
AddToCart | Someone added a catalog item to their cart on your website. |
Purchase | Someone purchased a catalog item from your website |
fbq('track', 'ViewContent') fbq('track', 'AddToCart') fbq('track', 'Purchase')
These events must contain specific parameters to help us match items on your website to items in your catalog:
Parameter name | Description | Requirement | Value type | Example |
---|---|---|---|---|
content_type | Tells Facebook to receive either a specific product ID or a product group ID, which is for variants of the same product. | Required | Must be either product or product_group. | product |
content_ids | Tells Facebook the specific content ID for a product or product group. The content ID must exactly match either the product ID or the product group ID for that item in your catalog, depending which content_type you entered. The match indicates it’s the same product or group as the one in your catalog. | You must use either content_ids or contents. Remember to always include the letter ‘s’ at the end of content_ids. | Can be either a single content ID or an array of content IDs (multiple IDs). | [‘123′,’456’] |
contents | Tells Facebook the specific content ID, which must match the product ID for that item in your catalog. If you use contents in your parameter, you must also include the following in a sub-object: the product id or ids, and the quantity (number of items added to cart or purchased). | You must use either content_ids or contents. | Must be an array of objects (content parameter, id sub-object and quantity sub-object). | [{id: ‘1234’, quantity: 2}] |
For example, the AddToCart event tracking code with content_ids and content_type parameters for the specific item looks like this:
fbq('track', 'AddToCart', { content_ids: ['1234','1853','9386'], content_type: 'product' });
After you add the required standard events and parameters to your website, you’ll need to connect your pixel to a catalog. This connection allows you to create dynamic ads that show people relevant items from your catalog. Learn how to connect a pixel to a catalog in Catalog Manager.