Meta Pixel Attribution Setup
Install Meta Pixel and Conversions API for accurate attribution. Get reliable tracking that survives iOS 14+ restrictions and ad blockers.
Meta Pixel Attribution Setup
TL;DR
Install Meta Pixel with server-side Conversions API for accurate attribution data that survives iOS 14+ restrictions and ad blockers—enabling better Meta algorithm optimization.
What you'll accomplish:
- Install Meta Pixel base code on your website for browser-side tracking
- Configure standard events (PageView, AddToCart, Purchase) with proper parameters
- Implement server-side Conversions API to bypass iOS tracking limitations
- Set up event deduplication preventing double-counting across pixel and API
- Connect Meta Ads and GA4 to Cogny for complete cross-platform attribution
Time required: 25 minutes | Difficulty: Intermediate | Prerequisites: Meta Business Manager, Meta Pixel created, website and server access (for CAPI)
Quick Start: Install Meta Pixel base code → Add standard event tracking → Test with Meta Pixel Helper extension → Verify events in Events Manager.
Related Resources
Essential guides for complete Meta tracking setup:
- Meta Ads Integration - Connect Meta Ads Manager to Cogny for campaign analysis
- Meta Ads AI Automation Playbook - Use pixel data to power AI-driven campaign optimization
- Server-Side Tracking Implementation - Bypass iOS restrictions with Conversions API
Question
How do I set up Meta Pixel properly to get accurate attribution data in Cogny?
Answer
Install Meta Pixel on your website. Configure Conversions API for server-side tracking. Send events to both GA4 and Meta. Connect GA4 BigQuery and Meta Ads to Cogny.
AI merges data from both sources for complete attribution picture.
Quick Tip: Implement the Conversions API (server-side) alongside the Pixel (browser-side) for 20-30% better attribution accuracy. iOS 14.5+ restrictions make browser-only tracking unreliable.
Why Accurate Meta Pixel Tracking Matters
Meta's algorithm needs accurate data. Without it:
- Poor campaign optimization
- Wasted budget
- Inaccurate ROAS reporting
With proper tracking:
- Meta AI optimizes better
- You see true performance
- Cogny's AI gets complete attribution data
What You'll Get
After setup:
Accurate conversion tracking Every purchase, signup, trial tracked reliably
Cross-device attribution Track same user on mobile and desktop
Server-side resilience Bypass ad blockers and browser restrictions
Complete customer journey See full path from Meta ad to conversion
Better AI optimization Both Meta's algorithm and Cogny's AI work with quality data
Note: iOS 14.5+ privacy changes limit browser-based tracking. Server-side tracking via Conversions API recovers 20-40% of lost events. Budget 2-4 developer hours for full implementation.
Prerequisites
You need:
- Meta Business Manager account
- Meta Pixel created (we'll show you how)
- Website access (to add tracking code)
- Server access (for Conversions API - optional but recommended)
Step 1: Create Meta Pixel
Go to business.facebook.com
Navigate to Events Manager
Click Connect Data Sources → Web
Click Meta Pixel → Connect
Pixel name: Your brand or website name (e.g., "Acme Store")
Click Continue
Time: 2 minutes
Step 2: Choose Installation Method
Meta offers three options:
Option A: Manual Installation (We'll use this)
- Full control
- Works with any platform
- Required for Conversions API
Option B: Partner Integration
- Shopify, WordPress, WooCommerce plugins
- Easier but less flexible
- May not support all features
Option C: Email Instructions
- Send to developer
- Use if you don't have website access
Select Manually Install the Code Yourself
Time: 1 minute
Step 3: Install Meta Pixel Base Code
Meta shows your pixel code:
<!-- Meta Pixel Code -->
<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>
<!-- End Meta Pixel Code -->
Add to your website:
Place in <head> section of all pages.
WordPress: Use "Insert Headers and Footers" plugin
Custom site: Add to header template
Shopify: Settings → Checkout → Additional scripts (paste in footer section instead)
Important: Replace YOUR_PIXEL_ID with your actual Pixel ID.
Time: 5 minutes
Step 4: Verify Pixel Installation
Install Meta Pixel Helper (Chrome extension):
Go to: chrome.google.com/webstore
Search: "Meta Pixel Helper"
Install extension.
Test your site:
Visit your website.
Click Meta Pixel Helper icon in browser.
Should show:
- ✅ Pixel found
- ✅ PageView event
- Pixel ID matches
Time: 3 minutes
Step 5: Set Up Standard Events
Meta has predefined events for common actions.
E-commerce events:
// View content (product page)
fbq('track', 'ViewContent', {
content_ids: ['SKU_12345'],
content_type: 'product',
content_name: 'Wireless Headphones',
content_category: 'Electronics',
value: 99.00,
currency: 'USD'
});
// Add to cart
fbq('track', 'AddToCart', {
content_ids: ['SKU_12345'],
content_type: 'product',
content_name: 'Wireless Headphones',
value: 99.00,
currency: 'USD'
});
// Initiate checkout
fbq('track', 'InitiateCheckout', {
content_ids: ['SKU_12345'],
content_type: 'product',
num_items: 1,
value: 99.00,
currency: 'USD'
});
// Add payment info
fbq('track', 'AddPaymentInfo', {
content_ids: ['SKU_12345'],
content_type: 'product',
value: 99.00,
currency: 'USD'
});
// Purchase
fbq('track', 'Purchase', {
content_ids: ['SKU_12345'],
content_type: 'product',
value: 99.00,
currency: 'USD'
});
SaaS events:
// Lead (newsletter signup, contact form)
fbq('track', 'Lead', {
content_name: 'Newsletter Signup',
value: 0,
currency: 'USD'
});
// Complete registration (account created)
fbq('track', 'CompleteRegistration', {
content_name: 'Free Account',
status: 'completed'
});
// Start trial
fbq('track', 'StartTrial', {
value: 0,
currency: 'USD',
predicted_ltv: 99.00
});
// Subscribe (paid conversion)
fbq('track', 'Subscribe', {
value: 99.00,
currency: 'USD',
predicted_ltv: 1188.00 // Annual value
});
Where to add these:
Add event code when action completes:
- ViewContent: On product page load
- AddToCart: After "Add to Cart" button click succeeds
- Purchase: On order confirmation page
Time: 10 minutes
Step 6: Configure Event Deduplication
Problem: You'll track events in multiple places:
- Browser (Meta Pixel)
- Server (Conversions API)
- GA4 (for Cogny)
Without deduplication, Meta sees duplicate conversions → inflated results.
Solution: Add event_id to each event.
In browser pixel:
fbq('track', 'Purchase', {
content_ids: ['SKU_12345'],
value: 99.00,
currency: 'USD'
}, {
eventID: 'purchase_12345_67890' // Unique ID for this specific purchase
});
Generate event_id:
// Combine order ID + timestamp
const eventID = `purchase_${orderId}_${Date.now()}`;
fbq('track', 'Purchase', {
value: orderTotal,
currency: 'USD'
}, {
eventID: eventID
});
Use same event_id for server-side event (Step 8).
Meta deduplicates automatically when event_id matches.
Time: 5 minutes
Step 7: Enable Advanced Matching
Advanced Matching sends hashed user data to Meta for better attribution.
Add user data to pixel init:
fbq('init', 'YOUR_PIXEL_ID', {
em: 'user@example.com', // Email (Meta auto-hashes)
fn: 'john', // First name (lowercase)
ln: 'doe', // Last name (lowercase)
ph: '15551234567', // Phone (digits only, include country code)
external_id: 'USER_12345' // Your user ID
});
fbq('track', 'PageView');
For logged-in users:
// When user is logged in, update pixel with their info
fbq('init', 'YOUR_PIXEL_ID', {
em: '<%= current_user.email %>',
fn: '<%= current_user.first_name.downcase %>',
ln: '<%= current_user.last_name.downcase %>',
external_id: '<%= current_user.id %>'
});
Why this matters:
Better cross-device tracking. Meta matches pixel events to logged-in Facebook users. Improves attribution accuracy.
Privacy note: Meta hashes this data before sending. Never sends plain text to their servers.
Time: 5 minutes
Step 8: Set Up Conversions API (Server-Side)
Why server-side tracking?
Browser-based tracking (Pixel) has issues:
- Ad blockers block 20-40% of events
- Browser privacy settings block tracking
- Slow page loads delay event firing
- Users leaving page = lost events
Server-side tracking:
- ✅ Bypass ad blockers
- ✅ 100% reliable delivery
- ✅ No browser dependencies
- ✅ Better data quality
Set up Conversions API:
Step 8A: Generate Access Token
In Meta Events Manager:
Click Settings → Conversions API
Click Generate Access Token
Copy token (starts with EAAG...)
IMPORTANT: Keep this secret. Never expose in client-side code.
Time: 2 minutes
Step 8B: Send Server-Side Events
From your backend, send events to Meta's Conversions API.
Example: Node.js
const axios = require('axios');
const crypto = require('crypto');
async function sendMetaConversion(eventName, eventData, userData) {
const pixelId = 'YOUR_PIXEL_ID';
const accessToken = 'YOUR_ACCESS_TOKEN';
const url = `https://graph.facebook.com/v18.0/${pixelId}/events`;
// Hash user data
const hashData = (data) => {
return data ? crypto.createHash('sha256').update(data.toLowerCase()).digest('hex') : null;
};
const payload = {
data: [{
event_name: eventName,
event_time: Math.floor(Date.now() / 1000),
event_id: eventData.event_id, // Same as browser event for deduplication
event_source_url: eventData.source_url,
action_source: 'website',
user_data: {
em: hashData(userData.email),
ph: hashData(userData.phone),
fn: hashData(userData.firstName),
ln: hashData(userData.lastName),
external_id: userData.userId,
client_ip_address: userData.ip,
client_user_agent: userData.userAgent,
fbc: userData.fbc, // Facebook click ID (from cookie _fbc)
fbp: userData.fbp // Facebook browser ID (from cookie _fbp)
},
custom_data: {
value: eventData.value,
currency: eventData.currency,
content_ids: eventData.content_ids
}
}],
access_token: accessToken
};
await axios.post(url, payload);
}
// Usage
await sendMetaConversion('Purchase', {
event_id: `purchase_${orderId}_${timestamp}`,
source_url: 'https://yoursite.com/order-confirmation',
value: 99.00,
currency: 'USD',
content_ids: ['SKU_12345']
}, {
email: 'user@example.com',
phone: '15551234567',
firstName: 'John',
lastName: 'Doe',
userId: 'USER_12345',
ip: request.ip,
userAgent: request.headers['user-agent'],
fbc: request.cookies._fbc,
fbp: request.cookies._fbp
});
Example: Python
import hashlib
import requests
import time
def send_meta_conversion(event_name, event_data, user_data):
pixel_id = 'YOUR_PIXEL_ID'
access_token = 'YOUR_ACCESS_TOKEN'
url = f'https://graph.facebook.com/v18.0/{pixel_id}/events'
def hash_data(data):
return hashlib.sha256(data.lower().encode()).hexdigest() if data else None
payload = {
'data': [{
'event_name': event_name,
'event_time': int(time.time()),
'event_id': event_data['event_id'],
'event_source_url': event_data['source_url'],
'action_source': 'website',
'user_data': {
'em': hash_data(user_data['email']),
'ph': hash_data(user_data['phone']),
'fn': hash_data(user_data['first_name']),
'ln': hash_data(user_data['last_name']),
'external_id': user_data['user_id'],
'client_ip_address': user_data['ip'],
'client_user_agent': user_data['user_agent'],
'fbc': user_data.get('fbc'),
'fbp': user_data.get('fbp')
},
'custom_data': {
'value': event_data['value'],
'currency': event_data['currency'],
'content_ids': event_data['content_ids']
}
}],
'access_token': access_token
}
requests.post(url, json=payload)
# Usage
send_meta_conversion('Purchase', {
'event_id': f'purchase_{order_id}_{int(time.time())}',
'source_url': 'https://yoursite.com/order-confirmation',
'value': 99.00,
'currency': 'USD',
'content_ids': ['SKU_12345']
}, {
'email': 'user@example.com',
'phone': '15551234567',
'first_name': 'John',
'last_name': 'Doe',
'user_id': 'USER_12345',
'ip': request.remote_addr,
'user_agent': request.headers.get('User-Agent'),
'fbc': request.cookies.get('_fbc'),
'fbp': request.cookies.get('_fbp')
})
Critical fields for matching:
em(email) - Most importantfbp(Facebook browser ID) - From_fbpcookiefbc(Facebook click ID) - From_fbccookie (set when user clicks Meta ad)external_id(your user ID)client_ip_addressandclient_user_agent
More fields = better matching.
Time: 30 minutes (initial setup)
Step 9: Test Conversions API
Meta provides test tool:
In Events Manager:
Click Test Events
Copy test code: TEST12345
Add to your server-side event:
const payload = {
data: [...],
test_event_code: 'TEST12345', // Add this for testing
access_token: accessToken
};
Trigger event on your site.
Check Test Events tab in Events Manager.
Should show event with all details.
Remove test_event_code for production.
Time: 5 minutes
Step 10: Verify Dual Tracking (Browser + Server)
Best practice: Send events from BOTH browser and server.
Browser: Fires immediately, captures user context Server: Fires reliably, bypasses blockers
Check Event Quality Score:
In Events Manager:
Click your Pixel.
See Event Match Quality score.
Goal: 7.0+ (out of 10)
Low score means:
- Missing customer data
- Poor matching parameters
- Duplicate events not properly deduplicated
Improve score:
- Add Advanced Matching data
- Include fbp and fbc parameters
- Send from both browser and server
- Use proper event deduplication
Time: 5 minutes
Step 11: Configure Aggregated Event Measurement
iOS 14.5+ privacy changes limit browser tracking.
Meta uses "Aggregated Event Measurement" for iOS users.
Configure in Events Manager:
Click Aggregated Event Measurement
Click Configure Web Events
Verify your domain (proves you own the site)
Add events in priority order (max 8 events):
Priority 1: Purchase (most valuable) Priority 2: Subscribe or AddToCart Priority 3: InitiateCheckout Priority 4: Lead Priority 5: ViewContent etc.
Why priority matters:
If user completes multiple events, only highest-priority event is reported due to iOS restrictions.
Order them by business value.
Time: 10 minutes
Step 12: Send Meta Data to GA4
For complete attribution in Cogny, send Meta ad data to GA4 too.
Capture UTM parameters from Meta ads:
Meta ads should include UTM tags:
https://yoursite.com/product?utm_source=facebook&utm_medium=cpc&utm_campaign=summer_sale&utm_content=video_ad_v2
GA4 captures these automatically.
Also capture Facebook Click ID (fbclid):
When user clicks Meta ad, URL includes ?fbclid=...
Save this to GA4:
// Capture fbclid from URL
const urlParams = new URLSearchParams(window.location.search);
const fbclid = urlParams.get('fbclid');
if (fbclid) {
// Send to GA4 as user property
gtag('set', 'user_properties', {
facebook_click_id: fbclid
});
// Also save to cookie for server-side use
document.cookie = `_fbc=fb.1.${Date.now()}.${fbclid}; path=/; max-age=7776000`; // 90 days
}
Now Cogny can match GA4 conversions to Meta ad clicks.
Time: 10 minutes
Step 13: Connect to Cogny
If you've already connected:
- GA4 to BigQuery to Cogny
- Meta Ads to Cogny
You're done.
Cogny automatically merges:
- Meta Pixel events (via Meta Ads API)
- GA4 events (via BigQuery)
- Server-side events (via Meta Conversions API)
AI analyzes complete attribution picture.
Time: Already done if sources are connected
What Cogny Does With This Data
1. Multi-Touch Attribution
Cogny sees full customer journey:
"Customer 12345:
- Saw Meta ad (awareness) - Day 1
- Clicked ad, viewed product (interest) - Day 1
- Added to cart, didn't purchase (consideration) - Day 1
- Returned via email, viewed product again - Day 3
- Returned via Google search - Day 5
- Purchased - Day 5"
Attribution models:
- Last-click: Google gets 100% credit
- First-click: Meta gets 100% credit
- Linear: Each touchpoint gets 20%
- Time-decay: Later touchpoints weighted higher
- Data-driven: AI determines contribution
2. True ROAS Calculation
Meta Ads Manager shows: ROAS = Revenue attributed to Meta / Ad spend
Cogny shows: True ROAS = (Revenue - Returns - Discounts - Cost of Goods) / (Ad spend + Attribution-adjusted cost)
Accounts for:
- Multi-touch attribution (not just last-click)
- Returns and refunds
- Discount impact
- Incrementality (would purchase have happened anyway?)
3. Creative Performance Analysis
"Video Ad V2:
- High CTR (2.4%)
- Low conversion rate (1.2%)
- Conclusion: Good at grabbing attention, poor at converting
Static Ad V5:
- Medium CTR (1.8%)
- High conversion rate (4.7%)
- Conclusion: Attracts right audience, converts well
Recommendation: Use Video V2 for prospecting (awareness), Static V5 for retargeting (conversion)."
4. Audience Insights
"Lookalike 1% audience:
- Good CTR
- Poor LTV (average $87)
- High churn rate
Warm retargeting (site visitors):
- Lower CTR
- High LTV (average $342)
- Low churn
Recommendation: Shift 40% budget from Lookalike to Retargeting."
Common Issues
"Pixel found but events not firing"
Check:
- Event code placed correctly? (after action completes)
- JavaScript errors? (check browser console)
- Ad blockers disabled? (for testing)
Use Meta Pixel Helper to see which events fire.
"Event Match Quality score is low"
Add more user data:
- Email (most important)
- Phone
- First name, last name
- external_id
- fbp and fbc cookies
- IP and user agent (server-side)
"Conversions API events not appearing"
Check:
- Access token valid?
- Pixel ID correct?
- Event payload properly formatted?
- Using test event code to debug?
View Diagnostics tab in Events Manager for error details.
"Duplicate events (2x conversions)"
Not using event deduplication.
Make sure:
- Browser and server events have SAME event_id
- event_id is unique per actual event
- event_time is same for browser and server
"iOS conversions missing"
iOS 14.5+ restricts tracking.
Solutions:
- Configure Aggregated Event Measurement (Step 11)
- Use Conversions API (bypasses browser)
- Implement Advanced Matching
- Verify your domain
Won't be perfect, but improves coverage.
Pro Tips
1. Track micro-conversions
Don't just track Purchase.
Track steps leading to purchase:
- ViewContent
- AddToCart
- InitiateCheckout
- AddPaymentInfo
Meta's algorithm optimizes better with full funnel data.
2. Use value parameter for all events
Even non-purchase events:
fbq('track', 'Lead', {
value: 10.00, // Estimated lead value
currency: 'USD'
});
Helps Meta optimize for valuable leads.
3. Send subscription value as predicted_ltv
fbq('track', 'Subscribe', {
value: 99.00, // This month's revenue
currency: 'USD',
predicted_ltv: 1188.00 // Annual value
});
Meta optimizes for long-term value, not just immediate revenue.
4. Use custom conversions for funnel analysis
In Events Manager: Custom Conversions
Create rules like:
- "Initiate Checkout - High Value" = InitiateCheckout event where value >= 200
- "Purchase - First Time" = Purchase event where custom parameter new_customer = true
Track different user segments separately.
5. Implement fingerprinting fallback
When user data unavailable, use browser fingerprinting:
const fingerprintData = {
screen: `${screen.width}x${screen.height}`,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
language: navigator.language
};
fbq('track', 'ViewContent', {
content_ids: ['SKU_12345']
}, {
eventID: eventID,
external_id: hashFingerprint(fingerprintData) // Fallback ID
});
Improves matching when email unavailable.
6. Monitor Event Manager daily
Check for:
- Event Match Quality drops
- Conversions API errors
- Pixel errors
- iOS 14+ impact
Fix issues immediately to maintain data quality.
What You Can Do Now
Immediate actions:
-
Audit current tracking
- Check Event Match Quality score
- Review events firing
- Verify deduplication working
-
Implement missing events
- Add full funnel tracking
- Set up Conversions API
- Enable Advanced Matching
-
Connect to Cogny
- Ensure GA4 and Meta Ads connected
- Verify data flowing to BigQuery
- Start AI analysis
-
Optimize based on insights
- Review multi-touch attribution
- Adjust campaign strategy
- Improve creative based on data
Next Steps
Immediate actions:
- Install Meta Pixel and verify events are firing correctly
- Implement Conversions API for critical events (purchases, signups)
Advanced implementation:
- Server-Side Tracking Implementation - Complete Conversions API setup for 100% reliability
- Meta Ads AI Automation Playbook - Use pixel data for AI-driven campaign optimization
Need help? Contact support
FAQ
Q: Do I need both Pixel and Conversions API?
Recommended: Yes.
Pixel: Immediate firing, rich browser context Conversions API: Reliable delivery, bypasses blockers
Best results: Both (with deduplication).
Minimum: Pixel only.
Q: How accurate is Meta attribution vs. Cogny's attribution?
Meta attribution:
- Last-click or 7-day click, 1-day view
- Only sees Meta touchpoints
- Optimized for Meta's algorithm
Cogny attribution:
- Multi-touch across all channels
- Sees complete customer journey
- Data-driven model
Both are useful for different purposes.
Q: Will Conversions API increase costs?
No.
Conversions API is free. Only costs: Your server resources (minimal).
Q: What's event_id vs. external_id?
event_id: Unique identifier for THIS specific event (for deduplication) external_id: Unique identifier for THIS user (for matching across sessions)
Different purposes.
Q: How long until Meta's algorithm uses new data?
Meta's learning phase:
- ~50 conversions per week per ad set
- Takes 1-2 weeks to stabilize
Changes to tracking may reset learning phase.
Q: Can I track offline conversions?
Yes.
Use Conversions API to send offline events:
- Store purchases
- Phone orders
- In-person signups
Same API, just set action_source to appropriate value:
physical_storephone_callother
Q: What about GDPR and privacy?
Meta Pixel requires user consent in EU.
Implement consent management:
- Use cookie consent tool (OneTrust, Cookiebot, etc.)
- Initialize Pixel with consent mode:
fbq('consent', 'revoke'); // Default: no consent
// After user accepts
fbq('consent', 'grant');
fbq('track', 'PageView');
- Document in privacy policy
Conversions API: Server-side, but still requires user consent if you're tracking personal data.
Ready for Accurate Attribution?
Most businesses lose 20-40% of conversion data to:
- Ad blockers
- Browser privacy settings
- Incomplete tracking
- Poor event setup
You're optimizing Meta campaigns on incomplete data. Making decisions based on 60% of reality.
Proper setup = complete picture = better decisions.
Not set up yet?
Schedule a demo and we'll audit your Meta Pixel setup and show you what's missing.
About This Guide
Written by the Cogny team—built by the founders who created AI optimization systems for Netflix, Zalando, and Momondo at Campanja, and scaled growth for Kry, Epidemic Sound, and Yubico through GrowthHackers.se.
We've set up Meta Pixel and Conversions API for hundreds of businesses. This is the proven approach.
Last Updated: January 6, 2025
See Cogny in Action
Schedule a demo to see how AI can transform your marketing analytics and automate your growth optimization.
Schedule Demo