Conversion Tracking

You can use the Meta Pixel to track your website visitors' actions also known as conversion tracking. Tracked conversions appear in the Facebook Ads Manager and the Facebook Events Manager, where they can be used to analyze the effectiveness of your conversion funnel and to calculate your return on ad investment. You can also use tracked conversions to define custom audiences for ad optimization and Advantage+ catalog ads campaigns. Once you have defined custom audiences, we can use them to identify other Facebook users who are likely to convert and target them with your ads.

There are three ways to track conversions with the Pixel:

  • standard events, which are visitor actions that we have defined and that you report by calling a Pixel function
  • custom events, which are visitor actions that you have defined and that you report by calling a Pixel function
  • custom conversions, which are visitor actions that are tracked automatically by parsing your website's referrer URLs

Requirements

The Pixel's base code must already be installed on every page where you want to track conversions.

Standard Events

Standard events are predefined visitor actions that correspond to common, conversion-related activities, such as searching for a product, viewing a product, or purchasing a product. Standard events support parameters, which allow you to include an object containing additional information about an event, such as product IDs, categories, and the number of products purchased.

For a full list of Standard events visit the Pixel Standard Events Reference. Learn more about Standard events with Blueprint.

Tracking Standard Events

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});

If you called that function, it would be tracked as a purchase event in the Events Manager:

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.

For example, if you wanted to track a standard purchase event after a visitor has completed the purchase, you could call the fbq('track') function on your purchase confirmation page, like this:

<body>
  ...
  <script>
    fbq('track', 'Purchase', {currency: "USD", value: 30.00});
  </script>
  ...
</body>

If instead you wanted to track a standard purchase event when the visitor clicks a purchase button, you could tie the fbq('track') function call to the purchase button on your checkout page, like this:

<button id="addToCartButton">Purchase</button>
<script type="text/javascript">
  $('#addToCartButton').click(function() {
    fbq('track', 'Purchase', {currency: "USD", value: 30.00});
  });
</script>

Note that the example above uses jQuery to trigger the function call, but you could trigger the function call using any method you wish.

Custom Events

If our predefined standard events aren't suitable for your needs, you can track your own custom events, which also can be used to define custom audiences for ad optimization. Custom events also support parameters, which you can include to provide additional information about each custom event.

Learn more about custom events with Blueprint.

Tracking Custom Events

You can track custom events by calling the Pixel's fbq('trackCustom') function, with your custom event name and (optionally) a JSON object as its parameters. Just like standard events, you can call the fbq('trackCustom') function anywhere between your webpage's opening and closing <body> tags, either when your page loads, or when a visitor performs an action like clicking a button.

For example, let's say you wanted to track visitors who share a promotion in order to get a discount. You could track them using a custom event like this:

fbq('trackCustom', 'ShareDiscount', {promotion: 'share_discount_10%'});

Custom event names must be strings, and cannot exceed 50 characters in length.

Custom Conversions

Each time the Pixel loads, it automatically calls fbq('track', 'PageView') to track a PageView standard event. PageView standard events record the referrer URL of the page that triggered the function call. You can use these recorded URLs in the Events Manager to define visitor actions that should be tracked.

For example, let's say that you send visitors who subscribe to your mailing list to a thank you page. You could set up a custom conversion that tracks website visitors who have viewed any page that has /thank-you in its URL. Assuming your thank you page is the only page with /thank-you in its URL, and you've installed the Pixel on that page, anyone who views it will be tracked using that custom conversion.

Once tracked, custom conversions can be used to optimize your ad campaigns, to define custom audiences, and to further refine custom audiences that rely on standard or custom events. Learn more about custom conversions with Blueprint.

Since custom conversions rely on complete or partial URLs, you should make sure that you can define visitor actions exclusively based on unique strings in your website URLs.

Creating Custom Conversions

Custom conversions are created entirely within the Events Manager. Refer to our Advertiser Help document to learn how.

Rule-Based Custom Conversions

Optimize for actions and track them without adding anything to your Meta Pixel base code. You can do this beyond the 17 standard events.

  1. Create a custom conversion at /{AD_ACCOUNT_ID}/customconversions.
  2. Specify a URL, or partial URL, representing an event in pixel_rule. For example, thankyou.html is a page appearing after purchase.

This records a PURCHASE conversion when 'thankyou.html' displays:

use FacebookAds\Object\CustomConversion;
use FacebookAds\Object\Fields\CustomConversionFields;

$custom_conversion = new CustomConversion(null, 'act_<AD_ACCOUNT_ID>');
$custom_conversion->setData(array(
  CustomConversionFields::NAME => 'Example Custom conversion',
  CustomConversionFields::PIXEL_ID => <PIXEL_ID>,
  CustomConversionFields::PIXEL_RULE => array(
    'url' => array('i_contains' => 'thank-you.html'),
  ),
  CustomConversionFields::CUSTOM_EVENT_TYPE => 'PURCHASE',
));
$custom_conversion->create();
from facebookads.adobjects.customconversion import CustomConversion

    custom_conversion = CustomConversion(parent_id='act_<AD_ACCOUNT_ID>')
    custom_conversion.update({
        CustomConversion.Field.name: 'Example Custom Conversion',
        CustomConversion.Field.pixel_id: <PIXEL_ID>,
        CustomConversion.Field.pixel_rule: {
            'url': {'i_contains': 'thankyou.html'},
        },
        CustomConversion.Field.custom_event_type: 'PURCHASE',
    })

    custom_conversion.remote_create()
curl \
  -F 'name=Example Custom conversion' \
  -F 'pixel_id=<PIXEL_ID>' \
  -F 'pixel_rule={"url":{"i_contains":"thank-you.html"}}' \
  -F 'custom_event_type=PURCHASE' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.8/act_<AD_ACCOUNT_ID>/customconversions

You can then create your campaign using the CONVERSIONS objective.

At the ad set level, specify the same custom conversion (pixel_id, pixel_rule, custom_event_type) in promoted_object.

Custom Conversions Insights

Ads Insights returns information about Custom Conversions:

curl -i -G \
-d 'fields=actions,action_values' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.7/<AD_ID>/insights

Returns both standard and custom conversions:

{
  "data": [
    {
      "actions": [
        {
          "action_type": "offsite_conversion.custom.17067367629523",
          "value": 1225
        },
        {
          "action_type": "offsite_conversion.fb_pixel_purchase",
          "value": 205
        }
      ],
      "action_values": [
        {
          "action_type": "offsite_conversion.custom.1706736762929507",
          "value": 29390.89
        },
        {
          "action_type": "offsite_conversion.fb_pixel_purchase",
          "value": 29390.89
        }
      ],
      "date_start": "2016-07-28",
      "date_stop": "2016-08-26"
    }
  ],
  "paging": {
    "cursors": {
      "before": "MAZDZD",
      "after": "MjQZD"
    },
    "next": "https://graph.facebook.com/v2.7/<AD_ID>/insights?access_token=<ACCESS_TOKEN>&amp;pretty=0&amp;fields=actions%2Caction_values&amp;date_preset=last_30_days&amp;level=adset&amp;limit=25&amp;after=MjQZD"
  }
}

Custom conversions have unique IDs; query it for a specific conversion, such as a rule-based one:

curl -i -G \
-d 'fields=name,pixel,pixel_aggregation_rule' \
-d 'access_token=ACCESS-TOKEN' \
https://graph.facebook.com/v2.7/<CUSTOM_CONVERSION_ID>

Custom Conversions Limitations

The maximum number of custom conversions per ad account is 100. If you use Ads Insights API to get metrics on custom conversions:

  • Getting product ID breakdowns are not supported.
  • Getting unique action counts are not supported.

Track Offsite Conversions

Track offsite conversions with your Pixels by adding the fb_pixel field to the tracking_spec parameter of your ad. Learn more.

use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;

$ad = new Ad(null, 'act_<AD_ACCOUNT_ID>');
$ad->setData(array(
  AdFields::ADSET_ID => <AD_SET_ID>,
  AdFields::CREATIVE => array(
    'creative_id' => <CREATIVE_ID>,
  ),
  AdFields::NAME => 'Offsite Conversions Ad',
  AdFields::TRACKING_SPECS => array(array(
    'action.type' => 'offsite_conversion',
    'fb_pixel' => <PIXEL_ID>,
  )),
));

$ad->create();
from facebookads.adobjects.ad import Ad

ad = Ad(parent_id='act_<AD_ACCOUNT_ID>')
ad.update({
    Ad.Field.adset_id: <AD_SET_ID>,
    Ad.Field.name: 'Offsite Conversions Ad',
    Ad.Field.creative: {
        'creative_id': <CREATIVE_ID>,
    },
    Ad.Field.tracking_specs: [
        {
            'action.type': 'offsite_conversion',
            'fb_pixel': <PIXEL_ID>,
        },
    ],
})
ad.remote_create(params={
    'status': Ad.Status.paused,
})
Ad ad = new AdAccount(act_<AD_ACCOUNT_ID>, context).createAd()
  .setAdsetId(<AD_SET_ID>)
  .setCreative(
    new AdCreative()
      .setFieldId(<CREATIVE_ID>)
  )
  .setName("Offsite Conversions Ad")
  .setTrackingSpecs("{\"action.type\":\"offsite_conversion\",\"fb_pixel\":\"" + <PIXEL_ID> + "\"}")
  .execute();
String ad_id = ad.getId();
curl \
  -F 'adset_id=<AD_SET_ID>' \
  -F 'creative={"creative_id":"<CREATIVE_ID>"}' \
  -F 'name=Offsite Conversions Ad' \
  -F 'tracking_specs=[{"action.type":"offsite_conversion","fb_pixel":"<PIXEL_ID>"}]' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/act_<AD_ACCOUNT_ID>/ads

Parameters

Parameters are optional, JSON-formatted objects that you can include when tracking standard and custom events. They allow you to provide additional information about your website visitors' actions. Once tracked, parameters can be used to further define any custom audiences you create. Learn more about parameters with Blueprint.

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.

For example, let's say you wanted to track a visitor who purchased multiple products as a result of your promotion. You could do this:

fbq('track', 'Purchase',
  // begin parameter object data
  {
    value: 115.00,
    currency: 'USD',
    contents: [
      {
        id: '301',
        quantity: 1
      },
      {
        id: '401',
        quantity: 2
      }],
    content_type: 'product'
  }
  // end parameter object data
);

Note that if you want to use data included in event parameters when defining custom audiences, key values must not contain any spaces.

Object Properties

You can include the following predefined object properties with any custom events and any standard events that support them. Format your parameter object data using JSON.

Property KeyValue TypeParameter Description

content_category

string

Category of the page or product.

content_ids

array of integers or strings

Product IDs associated with the event, such as SKUs. Example: ['ABC123', 'XYZ789'].

content_name

string

Name of the page/product.

content_type

string

Can be product or product_group based on the content_ids or contents being passed. If the IDs being passed in the content_ids or contents parameter are IDs of products, then the value should be product. If product group IDs are being passed, then the value should be product_group.

contents

array of objects

Array of JSON objects that contains the International Article Number (EAN) when applicable or other product or content identifier(s) associated with the event, and quantities and prices of the products. Required: id and quantity.

Example: [{'id': 'ABC123', 'quantity': 2}, {'id': 'XYZ789', 'quantity': 2}]

currency

string

Currency for the value specified.

delivery_category

string

Category of the delivery. Supported values:

  • in_store — Purchase requires customer to enter to the store.
  • curbside — Purchase requires curbside pickup
  • home_delivery — Purchase is delivered to the customer.

num_items

integer

Number of items when checkout was initiated. Used with the InitiateCheckout event.

predicted_ltv

integer, float

Predicted lifetime value of a subscriber as defined by the advertiser and expressed as an exact value.

search_string

string

String entered by the user for the search. Used with the Search event.

status

Boolean

Used with the CompleteRegistration event, to show the status of the registration.

value

integer or float

Value of a user performing this event to the business.

Custom Properties

If our predefined object properties don't suit your needs, you can include your own, custom properties. Custom properties can be used with both standard and custom events, and can help you further define custom audiences.

For example, let's say you wanted to track a visitor who purchased multiple products after having first compared them to other products. You could do this:

fbq('track', 'Purchase',
  // begin parameter object data
  {
    value: 115.00,
    currency: 'USD',
    contents: [
      {
        id: '301',
        quantity: 1
      },
      {
        id: '401',
        quantity: 2
      }],
    content_type: 'product',
    compared_product: 'recommended-banner-shoes',  // custom property
    delivery_category: 'in_store'
  }
  // end parameter object data
);

Next Steps

Now that you're tracking conversions, we recommend that you use them to define custom audiences, so you can optimize your ads for website conversions.

Learn More

  • Learn more about conversion tracking in a live training with Blueprint.