Setting up CAPI for Meta Pixel: a complete guide, errors and fixes
AnalyticsAdvanced

Setting up CAPI for Meta Pixel: a complete guide, errors and fixes

Meta is moving tracking to the server side. We walk through setting up the Conversions API, from creating a pixel to event deduplication.

PRoman Hrybuk
2024-10-0811 min

Meta is steadily moving tracking to the server side: ad blockers, browser restrictions and privacy policies are depriving the service of more and more client-side events. The Conversions API is a way to send conversion data directly from your server, bypassing the browser. Let’s go through the setup step by step and look at the errors that take the most time to fix.

Creating a Meta pixel

The pixel tracks user behavior on the website and sends data to Meta’s servers for analytics and ad optimization. If you don’t have a pixel yet, create one in Meta Events Manager — it’s the main tool for the subsequent API integration.

  • Link the pixel to the ad account you’ll be running campaigns from
  • Make sure the account has access to the pixel — otherwise some tracking features won’t be available
  • Check data transfer right away using the “Test Events” feature in Events Manager: there you can see every action the pixel sends from the website

Getting an access token

The access token is the key your server uses to send events to Meta. Without it, the connection between your server and Meta doesn’t work.

  1. Open Events Manager and find your pixel
  2. Click “Set up” and choose Conversions API
  3. Choose “Access Token” and generate it
  4. Copy the token and store it somewhere safe — you’ll need it when configuring the server
i
Tokens are usually long-lived, but still check their expiry. And never share the token with anyone: it grants the right to send events to your account.

Installing the pixel and API on the server

The choice of server depends on your technical level and the scale of the project:

  • Heroku — a simple option to start with: quick to deploy and doesn’t require deep knowledge
  • AWS — more flexibility and scalability, but a higher barrier to entry
  • DigitalOcean and other VPSs — for those who already have admin experience

Meta provides SDKs for Node.js, PHP and Python — pick the language you’re comfortable with.

npm install facebook-nodejs-business-sdk

Example of sending a purchase event from the server:

const bizSdk = require('facebook-nodejs-business-sdk');

const EventRequest = bizSdk.EventRequest;
const ServerEvent = bizSdk.ServerEvent;

const accessToken = 'YOUR_ACCESS_TOKEN';
const pixelId = 'YOUR_PIXEL_ID';

const event = new ServerEvent()
  .setEventName('Purchase')
  .setEventTime(Math.floor(new Date() / 1000))
  .setUserData({ email: 'user@mail.com' })
  .setCustomData({ currency: 'USD', value: 55.00 });

const eventRequest = new EventRequest(
  accessToken,
  pixelId
).setEvents([event]);

eventRequest.execute()
  .then(res => console.log('Event sent:', res))
  .catch(err => console.error('Send error:', err));

After setup, check data transfer using the “Test Events” feature in Events Manager — you’ll see right away whether data is arriving from your server.

Setting up events on the website

Events let you track key user actions and optimize campaigns correctly.

  • AddToCart — a product was added to the cart
  • InitiateCheckout — checkout was started
  • Purchase — a purchase was made
  • Lead — the user left their contact details
fbq('track', 'AddToCart', {
  content_ids: ['12345'],
  content_type: 'product',
  value: 25.00,
  currency: 'USD'
});

fbq('track', 'InitiateCheckout', {
  content_ids: ['12345'],
  content_type: 'product',
  value: 25.00,
  currency: 'USD'
});

fbq('track', 'Purchase', {
  value: 30.00,
  currency: 'USD'
});

fbq('track', 'Lead');

You can and should pass dynamic data in events — price, product ID, currency. This makes analytics more accurate and retargeting more effective: audiences of people who added a product to the cart but didn’t buy are built precisely from these events.

Common problems and how to fix them

An invalid or expired access token

The server can’t send events, and the logs show an authorization error. Check whether the token was generated correctly and whether it has expired; if it has, generate a new one and replace it in the code.

Events don’t fire or fire incorrectly

Most often, the code is placed in the wrong spot: the purchase event should be tied to the order confirmation page, not to a button. Check with “Test Events” and the Meta Pixel Helper extension — it shows events in real time.

Delayed or missing events in reports

A delay of up to a few minutes is normal. If there are still no events after a few hours, check the “Event History” section and the request logs between your server and Meta.

user_data validation errors

Meta rejects events with incorrect user data. The email address must be valid, and the phone number must be in the correct format. Personal data should be hashed before sending — it’s a Meta requirement and simply common sense.

Duplicates between the pixel and CAPI

The most common and most expensive mistake. If you send the same event through both the pixel and the API without an identifier, Meta will treat them as two separate events, and all your optimization goes to waste. The solution: pass the same event_id from both sides, and Meta will deduplicate them itself.

// Browser
fbq('track', 'Purchase', {
  value: 30.00,
  currency: 'USD'
}, {
  eventID: 'unique_event_id_123'
});

// Server
const event = new ServerEvent()
  .setEventName('Purchase')
  .setEventId('unique_event_id_123')
  .setEventTime(Math.floor(new Date() / 1000));

Ad blockers

Some users block the pixel on the client — events simply don’t arrive. This is exactly the problem CAPI solves: blockers can’t see server events. But don’t switch off the pixel — the “pixel + API” combination gives you the most complete data.

Integrations with e-commerce platforms

Shopify, WooCommerce and similar platforms set up events via plugins, and these integrations often work intermittently. Check the plugin version and exactly how it builds events — sometimes it’s easier to write your own code than to fix someone else’s.

Server environment configuration

Request timeouts, lack of network access, SSL issues — all of these get in the way of sending. On AWS and Heroku, check request limits separately.

Network errors and API unavailability

Sometimes Meta’s API is temporarily unavailable. Implement retry logic: the server should resend on a network error. And log every error — without logs, you won’t see that you’re losing conversions.

Conclusion

  • Check your access tokens and the correctness of the data you send
  • Use Meta’s testing tools: Pixel Helper and “Test Events”
  • Always set up deduplication by event_id when integrating the pixel and CAPI
  • Set up retry logic and logging on the server

The “pixel + Conversions API” combination with correct deduplication isn’t optional today — it’s a basic requirement for any revenue-generating project. You set it up once, and optimization quality noticeably improves.

Need a setup tailored to
your project?

We’ll review your current tracking, find where data is being lost and build a setup that works — free of charge.