Meta (Facebook) Ads Integration

Capture fbclid on landing, attribute affiliate conversions, and send purchase events to the Meta Pixel and Conversions API — with Enhanced Matching and server-side deduplication for accurate ROAS reporting.

Overview

When a visitor clicks a Meta ad and lands on your site, Meta appends fbclid to the URL. Affclix captures this alongside utk_click_id so every conversion is correctly attributed to both your affiliate and your Meta campaign.

  • fbclid auto-capture — stored in cookie + localStorage on landing, no manual code required
  • Meta Pixel (browser-side) — fires Purchase event from the thank-you page
  • Conversions API (server-side) — sends events directly from your server, bypassing ad blockers and iOS 14+ restrictions
  • Enhanced Matching — hashes PII for improved attribution match rates

fbclid Capture

Affclix captures fbclid automatically on every page load after init(). No extra configuration is needed.

JavaScript
AffclixSDK.init({
  trackingDomain: 't.yourdomain.com',
  cookieDomain:   '.yourdomain.com'
});

// Read captured fbclid at any time
var fbclid = AffclixSDK.getAttribution().fbclid;
console.log(fbclid); // e.g. "IwAR3x..."
fbclid lifetime

Meta's fbclid is valid for 7 days. The Affclix cookie TTL should be set to 7 days or less when operating in iOS 14+ environments to align with Meta's attribution window.

Pixel Setup

Load the Meta Pixel base code on all pages, then use the Affclix SDK to fire the Purchase event on the order confirmation page.

01

Add base pixel to all pages

Place the Meta Pixel base code in your layout before </head>. Do not fire any events in the base code.

02

Load Affclix SDK

Add AffclixSDK.init() on all pages to capture fbclid and UTM params on landing.

03

Fire Purchase on thank-you page

Use AffclixSDK.adPlatforms.meta.sendConversionEvent() — this fires both the Pixel event and the Affclix postback together.

HTML (thank-you page)
<!-- Meta Pixel base code (all pages, inside <head>) -->
<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>

<!-- Affclix SDK (all pages) -->
<script src="https://assets.affclix.com/sdk/v3/affclix-sdk.min.js"></script>
<script>
  AffclixSDK.init({
    trackingDomain: 't.yourdomain.com',
    cookieDomain:   '.yourdomain.com'
  });
</script>

Send Conversion

Call sendConversionEvent() on the order confirmation page. It fires the Meta Pixel Purchase event and the Affclix postback in a single call.

JavaScript
// The Pixel ID comes from your fbq base code (Step 1) — no need to repeat it.
AffclixSDK.adPlatforms.meta.sendConversionEvent('Purchase', {
  value:       99.00,
  currency:    'USD',
  order_id:    'ORDER-1001',
  content_ids: ['SKU-42', 'SKU-99'],
  num_items:   2
});
ParameterTypeRequiredDescription
eventName (1st argument)stringYesStandard event name: Purchase, Lead, CompleteRegistration
valuenumberYesConversion value
currencystringYesISO 4217 currency code
order_idstringNoUsed as event_id for deduplication between Pixel and CAPI
content_idsstring[]NoProduct SKUs in the order
num_itemsnumberNoTotal item quantity

Conversions API (CAPI)

Server-side Conversions API sends purchase events directly from your server to Meta, bypassing ad blockers, iOS tracking restrictions, and browser cookie limitations. This is the industry-standard approach used alongside the browser Pixel.

Best Practice: Pixel + CAPI together

Meta recommends firing both the browser Pixel and CAPI for every conversion. Use the same event_id (orderId) in both calls — Meta deduplicates them automatically.

HTTPS POST (from your server)
// 1. Configure a serverSideEndpoint at init — the SDK then POSTs the
//    Meta payload to YOUR server instead of calling fbq directly:
AffclixSDK.init({
  trackingDomain:     't.yourdomain.com',
  serverSideEndpoint: 'https://api.yourdomain.com/capi/forward'
});

AffclixSDK.adPlatforms.meta.sendConversionEvent('Purchase', {
  value: 99.00, currency: 'USD', order_id: '{ORDER_ID}'
});

// 2. Your endpoint receives this payload — forward it to the Meta
//    Conversions API (graph.facebook.com) with your CAPI access token:
{
  "platform":         "meta",
  "e":                "Purchase",
  "event_time":       1784548800,
  "event_source_url": "https://yourstore.com/thank-you",
  "user_data":        { "fbp": "fb.1....", "fbc": "fb.1....{fbclid}", "client_user_agent": "..." },
  "custom_data":      { "value": 99.00, "currency": "USD", "order_id": "{ORDER_ID}" }
}

Enhanced Matching

Pass hashed customer data to improve Meta's ability to match conversions to ad clicks, particularly for iOS 14+ users who have opted out of tracking.

JavaScript
// Enhanced matching is configured on the Pixel base code itself —
// Meta normalises and hashes these values client-side before sending.
fbq('init', 'YOUR_PIXEL_ID', {
  em:      'customer@example.com',
  ph:      '+919876543210',
  fn:      'Arjun',
  ln:      'Sharma',
  ct:      'Mumbai',
  zp:      '400001',
  country: 'in'
});

// Then fire the conversion — the Pixel attaches the matched user data
AffclixSDK.adPlatforms.meta.sendConversionEvent('Purchase', {
  value:    99.00,
  currency: 'USD',
  order_id: 'ORDER-1001'
});
Hashing

All PII is SHA-256 hashed by the SDK before transmission. Raw email, phone, or name values are never sent to Affclix or Meta servers in plain text.

Deduplication

When both Pixel and CAPI fire for the same order, Meta uses event_id to deduplicate and count only one conversion. Affclix enforces a matching rule: always pass orderId as the event_id in both the Pixel call and the CAPI postback.

SignalPixel (browser)CAPI (server)
event_idorderIdorderId (must match)
event_namePurchasePurchase
fbclidread from cookiepassed in payload
user datahashed via setUserData()hashed in server payload

Testing

Use the Meta Pixel Helper Chrome extension and Meta Events Manager Test Events tool to verify events are firing correctly before going live.

JavaScript
AffclixSDK.init({
  trackingDomain: 't.yourdomain.com',
  testMode:       true,  // marks Affclix postback as isTest
  debug:          true   // logs all SDK events to console
});
Test Event Code

When testing CAPI, pass your Meta Test Event Code in the postback payload as test_event_code. Events will appear in Events Manager → Test Events tab without affecting live campaign data.

Rate this article
★★★★★
Thanks for rating!

Was this article helpful?