SEO & Growth Engineering 10 min read

Meta Pixel and Conversions API Setup: Track Leads and Sales Accurately (Step by Step)

Set up the Meta Pixel and Conversions API so your ads optimise for real results: standard events, server-side events, deduplication with event IDs, customer data hashing, testing and match quality.

Umer Hasan

Umer Hasan

Co-Founder & CTO at Zapprex

Meta Pixel and Conversions API Setup: Track Leads and Sales Accurately (Step by Step)
Table of contents

Why tracking decides ad performance

Meta’s ad system learns from the conversions you report. If it only sees page views, it finds people who view pages. If it sees qualified leads and purchases, it finds more buyers. Browser-only tracking misses events because of ad blockers and privacy settings, so Meta recommends combining the Pixel (browser) with the Conversions API (server).

At a glance: Step 3: Test and improve — Test Events tool, Event Match Quality, Consent, Offline conversions
At a glance: Step 3: Test and improve

Step 1: Install the Pixel

Step 1: Install the Pixel: 4 steps
  1. 1

    Create a dataset: in Events Manager, connect a new web data source and copy the Pixel (dataset) ID.

  2. 2

    Add the base code: place it in the head of every page, or use your platform’s integration (Shopify, WooCommerce, Google Tag Manager).

  3. 3

    Track standard events: Lead, CompleteRegistration, ViewContent, AddToCart, InitiateCheckout and Purchase with values and currency.

  4. 4

    Verify your domain: in Business settings, so you can configure events and avoid restrictions.

Browser event with an event ID for deduplicationjavascript
const eventId = "lead-" + crypto.randomUUID()
fbq("track", "Lead", { content_name: "Website enquiry" }, { eventID: eventId })
// send the same eventId to your server with the form data

Step 2: Send server events with the Conversions API

When the form submission or order reaches your server, send the same event to Meta from the server with the same event_id. Meta deduplicates the browser and server copies. Customer details such as email and phone must be normalised and hashed with SHA-256 before sending.

Server event via Conversions API (Node.js)javascript
import crypto from "crypto"
const sha256 = (v) => crypto.createHash("sha256").update(v.trim().toLowerCase()).digest("hex")

await fetch("https://graph.facebook.com/v21.0/" + process.env.META_PIXEL_ID + "/events?access_token=" + process.env.META_CAPI_TOKEN, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    data: [{
      event_name: "Lead",
      event_time: Math.floor(Date.now() / 1000),
      event_id: eventId,                       // same as the browser event
      action_source: "website",
      event_source_url: "https://example.com/contact",
      user_data: {
        em: [sha256(email)],
        ph: [sha256("91" + phoneDigits)],
        client_ip_address: req.ip,
        client_user_agent: req.get("user-agent"),
      },
    }],
  }),
})

Step 3: Test and improve

“Report the events you actually care about. Optimising for “qualified lead” beats optimising for “form filled”.”

— Umer Hasan, CTO
  • Test Events tool: in Events Manager, send test events and confirm both browser and server events arrive and deduplicate.
  • Event Match Quality: improve it by sending more matching parameters such as email, phone and click ID (fbc) where you have consent.
  • Consent: respect your privacy policy and local laws — only send data you are allowed to share.
  • Offline conversions: send qualified-lead or closed-sale events from your CRM so ads optimise for real customers.

Topics

Meta PixelConversions APIConversion TrackingFacebook Ads
Umer Hasan
Written by

Umer Hasan

Co-Founder & CTO at Zapprex

Leads engineering, cloud infrastructure and AI automation at Zapprex Technologies, with 7+ years of full-stack and mobile experience.

FAQ

Questions readers ask

Meta recommends using both. The Pixel captures browser behaviour; the Conversions API sends reliable server-side events that are not blocked by browsers.

Have a project in mind?

Let's build something that moves your business forward.

Share your idea, process or problem — we will come back with a clear plan, timeline and cost range. No technical spec needed.

  • Founder reply within 1 business day
  • NDA on request · 100% code ownership
  • Talk directly to the engineers