All guides
Meta45 min· Advanced

Install the Meta Pixel + Conversions API end-to-end

The full 2026 setup: browser Pixel via GTM web, server-side Conversions API via sGTM, event deduplication via event_id, hashed customer data, and an Event Match Quality ≥ 7.

Before you start — you'll need
  • Meta Business Manager + Events Manager access
  • Pixel ID + ability to generate a CAPI Access Token
  • Server-side GTM container running on a first-party subdomain (Cloud Run / Stape / Addingwell)
  • GA4 ecommerce dataLayer already firing
By the end you'll have
  • Meta Pixel firing for PageView + standard events
  • Conversions API mirroring every event server-side
  • Deduplicated via event_id (Pixel + CAPI counted once)
  • Event Match Quality ≥ 7 in Events Manager
Step 1

Install the Meta Pixel template in web GTM

GTM web → Templates → Search Gallery → 'Facebook Pixel' by facebookincubator → Add. Then Tags → New → Facebook Pixel. Paste Pixel ID. Action: Init & Send PageView. Trigger: All Pages.

Step 2

Generate an event_id on every conversion

Every time your site pushes a conversion event into the dataLayer, generate a UUID and include it. This is what dedupes Pixel and CAPI.

function uuid() {
  return crypto.randomUUID
    ? crypto.randomUUID()
    : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
        (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
}

window.dataLayer.push({
  event: "purchase",
  event_id: uuid(),
  ecommerce: { /* as per GA4 guide */ },
  user_data: {
    email: "customer@example.com",   // raw — Pixel hashes
    phone: "+447700900000",
    first_name: "Luke",
    last_name: "Trevillion"
  }
});
Tip: Store the event_id in sessionStorage so refreshes of the thank-you page reuse it — never regenerate.
Step 3

Build the Pixel Standard Event tags

One Facebook Pixel tag per standard event. Action: Track Custom. Event name: Purchase (Meta's casing). Object Properties: map value, currency, content_ids, contents, num_items. Pass eventID = {{dlv - event_id}}. Trigger: CE – purchase.

Tip: Repeat for AddToCart, InitiateCheckout, Lead. Same event_id pattern.
Step 4

Add the Pixel Data Tag (forwards to sGTM)

Open the Facebook Pixel template → tick Enable First-Party Cookies. Then in More Settings → Server Container URL, paste your sGTM endpoint (e.g. https://sgtm.yourdomain.com). This forwards browser events to your sGTM container.

Step 5

Spin up the CAPI tag in sGTM

sGTM → Templates → Search Gallery → 'Conversions API Tag' by facebookincubator. Add it.

Tags → New → Conversions API Tag. Paste your Pixel ID + Access Token (generate in Events Manager → Settings → Conversions API → Generate access token).

Event Name: Purchase. Set Event Data → Inherit from event data.

Map user data fields: em, ph, fn, ln, fbc (from _fbc cookie), fbp (from _fbp cookie), client_ip_address, client_user_agent, event_id.

Tip: The template hashes em/ph/fn/ln for you — pass raw values.
Step 6

Trigger the CAPI tag on the right server event

sGTM triggers fire off the event the Pixel Data Tag forwarded. Create a trigger: Custom Event, name matches the Pixel event (Purchase). Bind to your Conversions API tag.

Repeat for AddToCart, InitiateCheckout, Lead.

Step 7

Test & verify EMQ

Events Manager → your pixel → Test Events. Open your site → complete a test purchase. You should see TWO entries that quickly collapse into ONE deduplicated event (badge: Deduplicated). Click into the event → Event Match Quality. Aim for ≥ 7.0.

Low EMQ usually means missing IP/UA forwarding, missing em/ph hashing, or unnormalised inputs (caps in emails, formatted phones).

Common pitfalls
  • Generating event_id in CAPI mapping (e.g. UUID at server side) — no dedupe, conversions double.
  • Pre-hashing email before pushing to dataLayer — template hashes again, mismatch, EMQ tanks.
  • Forgetting client_ip_address & client_user_agent — single biggest EMQ killer.
  • Running CAPI from BOTH your backend AND sGTM — pick one.
  • First-party cookie domain misconfigured — _fbp/_fbc cookies missing on the server side.
Official references
Keep going