What the Meta Pixel Does
The Meta Pixel is a JavaScript snippet that fires HTTP requests to Facebook's servers whenever a user takes an action on your site. These signals feed ad optimization, audience building, and conversion reporting inside Meta Ads Manager. Without it, Meta has no visibility into what happens after someone clicks your ad.
Install the Base Code
Place the base pixel snippet in the <head> of every page, before any other scripts. Replace YOUR_PIXEL_ID with the 15-16 digit ID from Events Manager.
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"
/></noscript>
The PageView event fires on every load. All other events build on top of this base.
Standard Events
Meta defines a set of standard events that unlock predefined optimization objectives. Fire them with fbq('track', 'EventName', {parameters}).
| Event | When to Fire | Key Parameters |
|---|---|---|
ViewContent |
Product or content page view | content_ids, content_type, value, currency |
AddToCart |
Item added to cart | content_ids, content_type, value, currency |
InitiateCheckout |
Checkout process starts | value, currency, num_items |
Purchase |
Order confirmation page | value, currency, content_ids, content_type |
Lead |
Form submission or signup | value, currency |
CompleteRegistration |
Account creation finishes | value, currency, status |
Example purchase event:
fbq('track', 'Purchase', {
value: 49.99,
currency: 'USD',
content_ids: ['SKU-1234'],
content_type: 'product',
});
Custom Events
For actions that do not map to standard events, use trackCustom:
fbq('trackCustom', 'PricingPageView', {
plan_type: 'enterprise',
});
Custom events can be used for audience building but cannot be selected as optimization objectives in campaigns.
Conversions API (CAPI) Server-Side Setup
The Conversions API sends events directly from your server to Meta, bypassing browser limitations like ad blockers and ITP. It is not a replacement for the pixel -- run both together for maximum signal.
A server-side Purchase event sent via CAPI:
curl -X POST \
"https://graph.facebook.com/v19.0/YOUR_PIXEL_ID/events?access_token=YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"data": [{
"event_name": "Purchase",
"event_time": 1709568000,
"event_id": "order-7891",
"action_source": "website",
"event_source_url": "https://example.com/thank-you",
"user_data": {
"em": ["309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd"],
"client_ip_address": "203.0.113.45",
"client_user_agent": "Mozilla/5.0..."
},
"custom_data": {
"value": 49.99,
"currency": "USD"
}
}]
}'
Hash all PII (email, phone, name) with SHA-256 before sending. Meta will never accept plaintext PII through the API.
Event Deduplication
When you send the same event through both the pixel and CAPI, Meta will double-count it unless you deduplicate. Pass an identical event_id in both channels:
Browser side:
fbq('track', 'Purchase', { value: 49.99, currency: 'USD' }, { eventID: 'order-7891' });
Server side: Include "event_id": "order-7891" in the CAPI payload (shown above). Meta matches on event_name + event_id within a 48-hour window and keeps only one.
Event Match Quality
Event Match Quality (EMQ) is a score from 1-10 in Events Manager that measures how well Meta can attribute events to real users. To improve it:
- Send
em(hashed email) andph(hashed phone) via Advanced Matching or CAPIuser_data - Include
fbp(first-party cookie_fbp) andfbc(click ID cookie_fbc) in CAPI requests - Pass
client_ip_addressandclient_user_agentfrom the original HTTP request
An EMQ of 6+ is considered good. Below 4 means Meta is struggling to match events to ad clicks.
iOS 14.5+ Aggregated Event Measurement
Apple's App Tracking Transparency framework limits the data Meta receives from iOS users. Under Aggregated Event Measurement (AEM), you can only optimize for 8 conversion events per domain, ranked by priority.
Setup steps:
- Verify your domain in Meta Business Settings under Brand Safety > Domains. Add a DNS TXT record or upload the verification HTML file.
- Go to Events Manager > Aggregated Event Measurement > Configure Web Events.
- Select your verified domain and rank up to 8 events. Put
Purchaseat the top if revenue optimization matters most. - Wait 72 hours after configuration changes before they take effect.
If a user opts out of tracking on iOS, Meta will only report the single highest-priority event from that session.
Testing and Validation
Meta Pixel Helper
Install the Meta Pixel Helper Chrome extension. It shows a badge count of events fired on each page and flags errors like missing parameters or duplicate pixels.
Test Events in Events Manager
Go to Events Manager > Test Events, enter your website URL, and browse your site. Events appear in real time with full parameter details. Use this to verify CAPI events are arriving and deduplication is working (you should see one event, not two, for each deduplicated action).
Diagnostics Tab
The Diagnostics tab in Events Manager surfaces issues like high event latency, low EMQ scores, parameter warnings, and inactive events. Check it weekly.