Meta Pixel, Conversions API and attribution

How do I set up the Conversions API for Facebook on WordPress?

On WordPress you can send Lead events to Meta through a plugin, a server-side GTM container or a small custom hook. Here is the full setup and dedup check.

Published

On WordPress you have three realistic routes to the Conversions API: a plugin that already sends server events (Meta’s own WordPress plugin, or a form plugin with a Meta integration), a server-side Google Tag Manager container, or a small custom hook that posts the Lead from your own PHP the moment a form is submitted. Whichever you choose, the event that matters is a Lead sent from your server with the same event_id as the browser Pixel, a hashed email and phone, and the fbc and fbp values from the visit.

What the Conversions API has to do on a WordPress site

Meta lists four setup options: the Meta-enabled option, partner integrations, the Conversions API Gateway and a direct integration. On WordPress, the partner route is a plugin, the Gateway route is a cloud container you host, and the direct route is your own code. The Meta-enabled option is worth switching on in Events Manager anyway, but it only shares what the Pixel already shares, so it does nothing for a visitor whose browser blocked the Pixel.

The test for any WordPress route is the same: does the Lead reach Meta from a server that saw the form submission? A form plugin that only fires fbq(‘track’, ‘Lead’) in the browser does not pass. A plugin or hook that posts to graph.facebook.com from PHP does. For what server events fix and what they cannot fix, read server-side tracking for Facebook ads.

Pick your route

Route on WordPressWhat it takesSends the Lead when the Pixel is blocked
Meta’s WordPress plugin or a form plugin’s Meta integrationinstall, connect the Pixel, map the form to Leadyes, if the plugin posts from the server; confirm in Test events
Server-side Google Tag Manager containera cloud container, a Meta tag, a data layer push on submityes
Custom hook in a small pluginPHP on the form’s submission action, POST to the Graph APIyes
Meta-enabled option onlyone click in Events Managerno

If your forms post to a backend you control, the custom hook gives you the most control and the fewest surprises. If a plugin already runs the integration, use it and spend your time on verification instead of code.

Step by step: connect WordPress to the Conversions API

  1. Get the Pixel ID and an access token. In Events Manager open Data sources, choose the Pixel, open Settings, find the Conversions API section and click Generate access token under Set up manually. The link only appears for users with developer privileges on the business. Keep the token in wp-config.php or an environment variable, never in theme or plugin JavaScript.
  2. Decide where the Lead is created. That is the hook your code listens to: the form plugin’s after-submission action, the order-created hook in WooCommerce, or a REST endpoint your form posts to.
  3. Capture the click identifiers on the visit. Read fbclid from the landing page URL, keep it with the session, and build fbc from it when the _fbc cookie is missing. Store _fbp as it is.
  4. Create one event_id per lead at submit time. Pass it to the browser Pixel as eventID and to your server code along with the form fields.
  5. Post the event. Send a POST to https://graph.facebook.com/{API_VERSION}/{PIXEL_ID}/events?access_token={TOKEN} with a data array holding one Lead: event_name, event_time in Unix seconds GMT, event_id, action_source set to website, event_source_url, and user_data with em and ph hashed with SHA-256, fbc and fbp in clear, client_ip_address and client_user_agent.
  6. Read the visitor’s IP and user agent, not the server’s. Behind Cloudflare or another proxy, take them from the forwarded headers on the request that submitted the form.
  7. Send immediately, and retry with the same event_id if the call fails. Meta rejects a request when any event in it is more than 7 days old, and keeps only the first copy of an event_name and event_id pair, so a retry cannot create a second lead.

The field-level rules for the payload, including which fields to hash, are in how to set up the Meta Conversions API for lead generation.

The event_id is what stops double counting

Meta pairs a browser event and a server event when the Pixel’s eventID matches the server’s event_id and the event names match, within 48 hours. Inside that window it keeps the first copy it received, and when the two arrive within 5 minutes of each other it favours the browser copy. Outside the window you get two leads for one form submission, which flatters your cost per lead and misleads budget decisions.

The usual WordPress failure is generating the ID twice: the Pixel creates one in JavaScript and the PHP code creates another. Generate it once, on submit, and pass the same string to both sides. Where the pairing breaks and how the fbp fallback behaves is covered in Facebook pixel event deduplication with the Conversions API.

Test it before you trust the numbers

Open Events Manager, go to Data sources, choose the Pixel and open the Test events tab. Copy the test code, add it as test_event_code at the top level of your request body next to data, then submit the form on your live landing page with your own email and phone. Check that the server Lead arrives with the parameters you expect and that its browser copy shows as deduplicated, then remove test_event_code before you go live.

One detail catches people out: events sent with a test code are not dropped. They flow into Events Manager and are used for targeting and measurement, so keep the number of tests small.

WordPress mistakes that break attribution

  • The access token sitting in theme JavaScript or a public repository.
  • Hashing fbc, fbp, the IP or the user agent, which Meta expects in clear.
  • Sending the server’s IP and user agent when the site sits behind a CDN.
  • Generating a separate ID in the Pixel and in PHP.
  • Firing the Lead on page load instead of on form submission.
  • Losing fbclid in a redirect chain before the landing page loads, so fbc can never be built.
  • Sending a Lead whose customer information is only a weak combination, which Meta treats as invalid.

Once the server event is live, compare the leads Meta reports with the rows in your own database for a few days. If your landing pages run outside WordPress on DropCPL, the click is logged first-party on your domain and the Lead is sent server-side with an event_id, fbc and fbp, so the WordPress side only has to keep the form and the Pixel consistent. More on match quality and attribution sits in Meta Pixel, Conversions API and attribution.

Questions on this topic

All questions on this topic →

FAQ

Do I need a developer to set up the Conversions API on WordPress?+

Not always. A plugin with a Meta integration can send server events after a few clicks, and the Meta-enabled option in Events Manager takes one click. A direct integration, where your own code posts the Lead, needs someone comfortable with PHP hooks and the Graph API. Meta estimates 2 to 4 weeks for a new direct integration.

Can I skip the Pixel once the Conversions API is running?+

No. Meta recommends running both, and its guidance targets the Conversions API covering 75% of your Pixel events. The Pixel still supplies browser signals and the fbp value used for matching. Keep both and deduplicate them with a shared event_id.

Why does my WordPress site show more leads in Meta than in my CRM?+

Usually a missing or mismatched event_id, so the browser Lead and the server Lead are both counted. Check that the Pixel's eventID and the server's event_id are the same string, and that the event names match exactly. Sending the server event more than 48 hours after the browser copy also produces a double count.

Does the Conversions API work with WooCommerce?+

Yes. WooCommerce is one of the commerce platforms with a Meta partner integration, so the plugin route can send server events without custom code. Confirm in Test events that the event arrives from the server with an event_id.

How do I improve Event Match Quality on WordPress?+

Send the email and phone hashed, plus fbc, fbp, the visitor's IP and user agent from the request that submitted the form. More matching fields raise the score. Sending only a weak combination such as a name and a city can make the event invalid.

Ready to find out what
converts, for real?

Free to start.

Start free →