Pixel for the Marketing API

The Meta Pixel is the main tool you can use to track events on a website. You can then use data from the Pixel with Marketing API to:

  • Build custom audiences based on activity on your website
  • Measure conversion activity and determine which ads lead to results such as purchases

Requirements

  • The Pixel's base code must already be installed on every webpage where you will be tracking events.

iOS 14.5 Updates

Due to the changes for iOS 14.5, we have introduced a new tool for tracking web events for iOS 14.5 ad campaigns.

Aggregated Event Measurement

Facebook’s Aggregated Event Measurement is a protocol that allows for measurement of web events from iOS 14.5 users. Aggregated Event Measurement limits domains to 8 conversion events that can be used for campaign optimization.

Visit our Domain Verification guide to verify your domain ownership for Aggregated Event Measurement.

Visit our Business Help Center to learn more.

Visit our Changelog for more information about other changes available.

Standard Events

The following examples are standard events that you can track.

Lead

Track the following Lead standard event on your website.

fbq(
  'track', 'Lead', {
    content_name: 'Auto Insurance',
    content_category: 'Quote',
    value: 40.00,
    currency: 'USD'
  }
);

ViewContent

Track the following ViewContent standard event on your website.

fbq(
  'track', 'ViewContent', { 
    content_type: 'product',
    content_ids: ['1234'],
    content_name: 'ABC Leather Sandal',
    content_category: 'Shoes'
    value: 0.50,
    currency: 'USD'
  }
);

Search

Track the following Search standard event on your website.

fbq(
  'track', 'Search', { 
    search_string: 'leather sandals',
    content_category: 'Product Search',
    content_ids: ['1234', '2424', '1318', '6832'],
    value: 0.50,
    currency: 'USD'
  }
);

Purchase

Track the following Purchase standard event on your website's payment confirmation page.

fbq(
  'track', 'Purchase', { 
    content_type: 'product',
    contents: [
      { 'id': '1234', 'quantity': 2, },
      { 'id': '4642', 'quantity': 1, }
    ],
    value: 25.00,
    currency: 'USD'
  }
);

Custom Events

Track a custom event specific to your website. Replace CUSTOM-EVENT-NAME with your custom event name and custom_parameter with your custom parameter name.

fbq(
  'trackCustom', 'CUSTOM-EVENT-NAME', {
    custom_parameter: 'ABC',
    value: 10.00,
    currency: 'USD'
  }
);

In-Page Events

Track in-page actions by tying standard or custom events to HTML elements such as buttons.

<button onClick="fbq('track', 'Purchase');">Button Text</button>

Create a function if you have multiple HTML elements.

<script>
function onClick() {
fbq('track', 'Purchase');
};
</script>

Call this function to track Purchase events for multiple HTML elements.

<button onClick="onClick()">Buy Now</button>

<button onClick="onClick()">Buy as a Gift</button>

Note: The Pixel Helper may show multiple Pixel events from the same page. The Pixel Helper expects to track only on load events but by tying events to elements, such as a button, you can use the Helper to track more event types.

Track a Specific Pixel

Track a single custom event from a specific Pixel. Replace PIXEL-ID with the Pixel ID you want to track.

<script>
  function onClick() {
    fbq(
      'trackSingleCustom', 'PIXEL-ID', 'PageView'
    );
  };
</script>

Note: The trackSingleCustom method does not validate custom data.

Suppress a Pixel

Suppress Pixels by using pushState or replaceState.

fbq.disablePushState = true;

Optimize Ad Delivery with Pixels

Optimize ad delivery based on standard events tracked using Pixels using the promoted_object field for the /act_AD-ACCOUNT/adsets endpoint.

The following example optizimes ads delivery based on purchase value using a Pixel that tracks puchase events.

Formatted for readability
curl -i -X POST "https://graph.facebook.com/v2.10/act_AD-ACCOUNT-ID/adsets
    ?name=Ad Set for Value Optimization
    &campaign_id=CAMPAIGN-ID
    &optimization_goal=VALUE
    &promoted_object={"pixel_id":"PIXEL-ID","custom_event_type":"PURCHASE"}
    &billing_event=IMPRESSIONS
    &daily_budget=1000
    &attribution_spec=[{'event_type': 'CLICK_THROUGH', 'window_days':'1'}]
    &access_token=ACCESS-TOKEN"

Note: Values for conversion_specs are automatically inferred based on the objective and promoted_object. You cannot manually set conversion_specs.

Image Only Pixel Code

We strongly recommend using the JavaScript code for Facebook Pixel. However, in some cases, you may use an HTML or an image Pixel then add another third party tag from your website.

Standard Events

<img src="https://www.facebook.com/tr?id=PIXEL-ID&amp;ev=ViewContent&amp;cd[content_name]=ABC%20Leather%20Sandal&amp;cd[content_category]=Shoes&amp;cd[content_type]=product&amp;cd[content_ids]=1234&amp;cd[value]=0.50&amp;cd[currency]=USD&amp;noscript=1" height="1" width="1" style="display:none"/>

Custom Events

<img src="https://www.facebook.com/tr?id=PIXEL-ID&amp;ev=CustomEventName&amp;cd[custom_param1]=ABC&amp;cd[custom_param2]=123&amp;cd[value]=10.00&amp;cd[currency]=USD&amp;noscript=1" height="1" width="1" style="display:none"/>

See Also