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.
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).

Step 1: Install the Pixel

- 1
Create a dataset: in Events Manager, connect a new web data source and copy the Pixel (dataset) ID.
- 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
Track standard events: Lead, CompleteRegistration, ViewContent, AddToCart, InitiateCheckout and Purchase with values and currency.
- 4
Verify your domain: in Business settings, so you can configure events and avoid restrictions.
const eventId = "lead-" + crypto.randomUUID()
fbq("track", "Lead", { content_name: "Website enquiry" }, { eventID: eventId })
// send the same eventId to your server with the form dataStep 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.
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”.”
- 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
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.
Keep reading
All articlesMeta Ads Guide for Beginners: How to Run Facebook and Instagram Ads That Bring Leads
A plain-English Meta ads tutorial: how campaigns, ad sets and ads fit together, choosing objectives, audiences and budgets, creatives that work, tracking with the Pixel and reading results.
Technical SEO & Core Web Vitals: Turning Millisecond Speed Gains into Organic Revenue
Google no longer ranks websites based purely on keywords. Discover how Interaction to Next Paint (INP), Largest Contentful Paint (LCP), and modern web architecture directly impact organic search rankings.
Mobile App Development Process, Step by Step: From Idea to Play Store (Beginner’s Guide)
A plain-English walkthrough of how a mobile app is actually built — discovery, wireframes, UI design, backend, testing, launch and updates — with what you should do at each stage and how long it takes.
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.
When the same event is sent from the browser and the server with the same event name and event ID, Meta counts it once instead of twice.
Customer data must be hashed and shared only in line with your privacy policy, user consent and applicable laws such as India’s DPDP Act. Take legal advice for your situation.
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
