The Meta Pixel is the main tool you can use to track events on a website. You can then use data from the Meta Pixel with Marketing API to:
Due to the changes for iOS 14.5, we have introduced a new tool for tracking web events for iOS 14.5 ad campaigns.
Meta's Aggregated Event Measurement is a protocol that allows for measurement of web and app events from people using iOS 14.5 or later devices. Statistical modeling may be used and is designed to provide a more complete view of results when data is missing or partial.
Aggregated Event Measurement currently limits domains and mobile apps to 8 conversion events that can be configured and prioritized for Aggregated Event Measurement.
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.
The following examples are standard events that you can track.
Track the following Lead
standard event on your website.
fbq( 'track', 'Lead', { value: 40.00, currency: 'USD' } );
Track the following ViewContent
standard event on your website.
fbq( 'track', 'ViewContent', { content_type: 'product', content_ids: ['1234'], value: 0.50, currency: 'USD' } );
Track the following Search
standard event on your website.
fbq( 'track', 'Search', { search_string: 'leather sandals', content_ids: ['1234', '2424', '1318', '6832'], value: 0.50, currency: 'USD' } );
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' } );
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' } );
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 single custom event from a specific Meta Pixel. Replace PIXEL-ID
with the Meta 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 Meta Pixels by using pushState
or replaceState
.
fbq.disablePushState = true;
Optimize ad delivery based on standard events tracked using Meta 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 readabilitycurl -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
.
We strongly recommend using the JavaScript code for Meta Pixel. However, in some cases, you may use an HTML or an image Meta Pixel then add another third party tag from your website.
<img src="https://www.facebook.com/tr?id=PIXEL-ID&ev=ViewContent&cd[content_type]=product&cd[content_ids]=1234&cd[value]=0.50&cd[currency]=USD&noscript=1" height="1" width="1" style="display:none"/>
<img src="https://www.facebook.com/tr?id=PIXEL-ID&ev=CustomEventName&cd[custom_param1]=ABC&cd[custom_param2]=123&cd[value]=10.00&cd[currency]=USD&noscript=1" height="1" width="1" style="display:none"/>