Skip to content
Learni
View all tutorials
Marketing Digital

How to Set Up Meta Ads from Pixel to Campaign in 2026

Lire en français

Introduction

In 2026, Meta Ads (Facebook, Instagram, Messenger, WhatsApp) account for over 50% of social ad spend thanks to precise targeting and high ROI. However, with privacy restrictions like ATT (iOS) and third-party cookies blocked, reliable tracking depends on a solid technical setup: the client-side Meta Pixel, standard events, and server-side Conversion API (CAPI). This beginner tutorial, designed for developers and junior marketers, guides you step-by-step from installing the pixel on your site to launching your first campaign in Ads Manager. You'll get complete, functional code (HTML, JS, Node.js, JSON) for a production-ready setup. By the end, you'll master the basics to scale your ads. Key point: Without pixel/CAPI, campaigns lose 30-50% of data, killing optimization. Ready to turn visitors into customers?

Prerequisites

  • A free Meta Business Manager account (create it at business.facebook.com).
  • A website or localhost (e.g., Vite, Next.js, or plain HTML).
  • Node.js 18+ installed for server-side examples.
  • Access to Events Manager in Business Manager.
  • Test budget: 10-50€ for a campaign.
  • Basic HTML/JS knowledge (no frameworks required).

Install the Base Meta Pixel

public/index.html
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Mon Site avec Meta Pixel</title>
  <!-- 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', 'VOTRE_PIXEL_ID_ICI'); // Remplacez par votre ID Pixel
    fbq('track', 'PageView');
  </script>
  <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=VOTRE_PIXEL_ID_ICI&ev=PageView&noscript=1"
  /></noscript>
  <!-- End Meta Pixel Code -->
</head>
<body>
  <h1>Bienvenue sur mon site !</h1>
  <button id="purchaseBtn">Acheter (test event)</button>
  <script src="events.js"></script>
</body>
</html>

This complete HTML code inserts the Meta Pixel via CDN in the , initializes it with your Pixel ID (from Events Manager), and tracks the automatic 'PageView'. The noscript provides an image fallback for JS blockers. Copy-paste it onto your site; replace 'VOTRE_PIXEL_ID_ICI' with the real ID for instant tracking. Pitfall: Don't forget the noscript, or 10-20% of events will be lost.

Verify and Test the Pixel

  1. Go to Business Manager > Events > Events Overview.
  2. Open your HTML page locally (using live-server or browser).
  3. Click 'Test Events', enter your domain/pixel ID.
  4. Refresh: 'PageView' should appear in green (20s delay).
Analogy: The pixel is like an invisible spy on your site, reporting visits to Meta. If red, check the ID or ad blockers (uBlock). Activate in Pixel Settings > Proceed to Domain Verification to validate business.facebook.com.

Add Standard Client-Side Events

public/events.js
document.getElementById('purchaseBtn').addEventListener('click', function() {
  fbq('track', 'Purchase', {
    value: 29.99,
    currency: 'EUR',
    content_ids: ['product123'],
    content_type: 'product',
    num_items: 1
  });
  alert('Événement Purchase tracké ! Vérifiez Events Manager.');
});

// Exemple AddToCart
fbq('track', 'AddToCart', {
  value: 29.99,
  currency: 'EUR',
  content_ids: ['product123'],
  content_type: 'product'
});

This JS script adds a listener to a button to track 'Purchase' with required params (value, currency). It also includes 'AddToCart' for e-commerce funnels. Integrate it into your real site by adapting selectors/params. Pitfall: Without 'content_ids', product optimization is weak; always use realistic values for tests.

Implement the Conversion API (CAPI) Server-Side

Why CAPI? It complements the client-side pixel (blocked by privacy tools) by sending events from the server. Gain: +15-30% more data.

  1. In Events Manager, create a CAPI Events Set linked to your pixel.
  2. Generate a System Access Token (Settings > System Tokens > Generate New).
  3. Implement in Node.js (next example). Test with curl.

Node.js Script for CAPI

server-capi.js
const https = require('https');

const PIXEL_ID = 'VOTRE_PIXEL_ID_ICI';
const ACCESS_TOKEN = 'VOTRE_TOKEN_CAPI_ICI';

const eventData = {
  data: [{
    event_name: 'Purchase',
    event_time: Math.floor(Date.now() / 1000),
    action_source: 'website',
    event_source_url: 'https://votre-site.com/checkout',
    event_id: 'unique-event-id-123',
    user_data: {
      em: 'hash@example.com', // hashed email
      client_ip_address: '123.123.123.123',
      client_user_agent: 'Mozilla/5.0...',
      fbp: 'fb.1.1234567890.abcdef',
      fbc: 'fb.1.1234567890.1234567890'
    },
    custom_data: {
      value: 29.99,
      currency: 'EUR',
      content_ids: ['product123'],
      content_type: 'product'
    }
  }],
  partner_agent: 'learni-dev-tutorial-2026'
};

const postData = JSON.stringify(eventData);

const options = {
  hostname: 'graph.facebook.com',
  port: 443,
  path: `/v20.0/${PIXEL_ID}/events?access_token=${ACCESS_TOKEN}`,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(postData)
  }
};

const req = https.request(options, (res) => {
  let data = '';
  res.on('data', (chunk) => { data += chunk; });
  res.on('end', () => { console.log('Réponse CAPI:', JSON.parse(data)); });
});
req.on('error', console.error);
req.write(postData);
req.end();

console.log('Envoi CAPI Purchase...');

This Node.js script sends a 'Purchase' event via HTTPS to the Graph API (v20.0 in 2026). Replace PIXEL_ID/ACCESS_TOKEN; hash emails with sha256 for privacy. Run with node server-capi.js. Pitfall: Unique 'event_id' is required for pixel/CAPI deduplication; without IP/UA, matching is weak.

Test CAPI with curl

test-capi.sh
#!/bin/bash
PIXEL_ID="VOTRE_PIXEL_ID_ICI"
ACCESS_TOKEN="VOTRE_TOKEN_CAPI_ICI"

curl -X POST \
  -F 'data=[{"event_name":"Purchase","event_time":'$(date +%s)',"action_source":"website","event_id":"test-123","user_data":{"em":["hash123"]},"custom_data":{"value":29.99,"currency":"EUR"}}]' \
  -F 'partner_agent=learni-dev-2026' \
  "https://graph.facebook.com/v20.0/$PIXEL_ID/events?access_token=$ACCESS_TOKEN"

# Check Events Manager: event should appear in 5min.

This bash curl script tests a minimal event without Node.js. Copy to a .sh file, chmod +x, and run. Great for quick debugging. Pitfall: Use multipart format for the data array; always test before production to avoid API quotas (200 calls/min).

Create Your First Campaign in Ads Manager

  1. Business Manager > Ads Manager > Create.
  2. Objective: Sales (for Purchase).
  3. Ad Set: New audience (France, 18-45, e-commerce interests).
  4. Budget: 10€/day, 7 days.
  5. Placements: Automatic (FB/IG Feed/Stories).
  6. Creative: Image + '30% Off!' text + site link.
  7. Publish and monitor Columns > Performance.
Tip: Link your pixel/events set for automatic optimization.

Create a Campaign via Marketing API (Bonus)

create-campaign.json
{
  "name": "Ma Campagne Test Learni 2026",
  "objective": "CONVERSIONS",
  "status": "PAUSED",
  "special_ad_categories": [],
  "access_token": "VOTRE_AD_ACCOUNT_TOKEN",
  "ad_account_id": "act_VOTRE_AD_ACCOUNT_ID"
}

This JSON payload creates a campaign via POST /v20.0/act_{AD_ACCOUNT_ID}/campaigns. Use with curl or SDK. Get AD_ACCOUNT_ID from Business Settings. Pitfall: 'objective' must match your events; always set to PAUSED for manual review.

Best Practices

  • Deduplication: Always use a unique 'event_id' (UUID) between pixel/CAPI.
  • Privacy Hashing: Sha256 for em/ph/gef (email/phone) before sending.
  • Verified Domains: Validate 3+ domains in Pixel Settings for full CAPI.
  • A/B Tests: Duplicate events sets to compare pixel vs CAPI.
  • Monitoring: Enable event quality alerts (>8/10 green).

Common Errors to Avoid

  • Wrong Pixel ID: Check format (123456789012345); 'Invalid Parameter' error.
  • No CAPI: Lose 40% events on mobile; implement from day 1.
  • Forgot Hashing: Events rejected for privacy; use Meta helpers.
  • Budget Without Audience: Target cold traffic first, retarget after 100 events.

Next Steps