Contact Form 7 and Meta Pixel: track each Lead once

To track Contact Form 7 in the Meta Pixel (formerly Facebook Pixel) without duplicates, send the Lead only when Contact Form 7 reports mail_sent: the form was accepted and its email went out. Not on the click, not on a validation error, and not again when the same person submits a second time.

Why one submission must mean one Lead

Meta uses your Lead events to decide who to show your ads to. If one person who filled in your Contact Form 7 form is counted twice, or a person whose submission failed is counted at all, the reports overstate your results and the delivery system learns from people who never became leads. The goal is simple: exactly one Lead for each submission that Contact Form 7 actually accepted, and none for failed or repeated ones.

Three setups break that rule on almost every site:

  • Counting the button click. The visitor clicks Submit, a required field is empty, the form shows an error, and the Lead has already gone. A second click after fixing the field sends another.
  • Counting every load of a thank-you page. A reload, the back button or a bookmark sends the event again.
  • Two tools tracking the same form. A pixel plugin, a tag manager trigger and theme code can each send their own Lead for the same submission.

How Contact Form 7 submits a form

Contact Form 7 submits in the background and stays on the same page. The browser sends the form to its REST endpoint, an address ending in /wp-json/contact-form-7/v1/contact-forms/<form id>/feedback, and the server answers with JSON that includes a status field. The request usually returns HTTP 200 whatever the outcome, so the status code tells you nothing; the status value does:

  • mail_sent: the submission was accepted and the email was sent. This is the only value that is a lead.
  • validation_failed: a field was missing or invalid, and the form shows an error.
  • spam: the submission was treated as spam (for example by a CAPTCHA or Akismet check).
  • mail_failed: the form was valid but the email could not be sent. Most sites do not count this, because nobody received the enquiry.

Contact Form 7 also announces the result in the page with DOM events on the form, including wpcf7submit (any submission, successful or not), wpcf7invalid, wpcf7spam, wpcf7mailfailed and wpcf7mailsent.

Which signal to use

SignalWhat it tells youUse it for the Lead?
Click on the Submit buttonSomeone tried to send the formNo
wpcf7submit eventA submission finished, with any resultNo
wpcf7mailsent eventThe form was accepted and the email sentYes
Response status: mail_sentThe same, read from the server's answerYes
The message box under the formShows errors as well as the thank-you textNo, it appears on failures too

Before you choose, look at what your own form does: open the browser's developer tools, go to the Network tab, submit the form once with a mistake and once correctly, and compare the two requests and their answers. Form plugins change between versions, and add-ons can change how a form submits.

Option 1: your own code

If you add the pixel yourself, listen for wpcf7mailsent and nothing else. The event bubbles to document, so one listener covers every form; event.detail.contactFormId tells you which form it was.

document.addEventListener('wpcf7mailsent', function (event) {
  var id = 'lead-' + Date.now() + '-' + Math.random().toString(36).slice(2);
  fbq('track', 'Lead', { content_name: 'Form ' + event.detail.contactFormId }, { eventID: id });
});

This works, but it needs a code snippet plugin or theme changes, and it still sends a second Lead if the same person submits twice. If you also send the event from your server with the Conversions API, give both copies the same event ID so Meta keeps one; see how Meta deduplicates with event_id.

Option 2: Pixelonce, without code

Pixelonce, a free WordPress plugin, tracks Contact Form 7 forms with bindings: rules that turn something the site does into an event, without editing the theme or the form plugin. Add the binding under Pixelonce → Bindings, then on the page that holds the form add the Lead event with the trigger “When the site signals it”.

Use an ajax binding that matches the Contact Form 7 endpoint by part of its address and requires the mail_sent status. Pixelonce watches both jQuery requests and fetch, which current Contact Form 7 versions use. To track only one form, add its ID to the address, for example contact-forms/123/feedback.

{
  "type": "ajax",
  "emit": "Lead",
  "url": "contact-form-7/v1/contact-forms/",
  "require_success": true,
  "success_when": { "status": "mail_sent" }
}

A binding only signals; the event's “how often” setting decides whether it fires. Set the Lead to once per visitor (or once per session) and a person who submits the form twice still counts as one lead. Every Lead gets one event ID, which the Conversions API copy reuses, so Meta pairs the browser and server copies instead of counting both.

Contact Form 7 traps to avoid

  • Don't rely on the message box. The .wpcf7-response-output area under the form shows validation errors and spam warnings as well as the thank-you text, so a rule that fires when it appears also counts failures.
  • Redirecting to a thank-you page. Some sites redirect after wpcf7mailsent with a snippet or an add-on. If you do, fire the Lead either on the event or on the thank-you page, not on both, and limit the thank-you page event to once per session so reloads don't count.
  • Spam protection. With a CAPTCHA or Akismet, blocked submissions come back as spam. Requiring mail_sent keeps them out of your leads automatically.
  • Page caching. Contact Form 7 forms work on cached pages, but a cached page can hold an expired security token for a while. If submissions start failing after you enable a cache, the failures are real and should not be counted, which is exactly what this setup does.

Test it before you trust it

  1. Remove any other Lead tracking for this form, so only one tool sends it.
  2. Open Events Manager → Test events, and open your form page from there.
  3. Submit the form with a required field empty: no Lead should arrive.
  4. Submit it correctly: exactly one Lead should arrive (two rows if you also use the Conversions API, marked as deduplicated).
  5. Reload the page and submit again: with once per visitor, nothing new should arrive.

With Pixelonce you can also add ?stepcount_debug=1 to the page address: the debug overlay shows each decision, including a submission that was ignored because Contact Form 7 did not report success. If you still see doubled events, work through Meta Pixel firing twice on WordPress.

Pixelonce has no official integration with or endorsement from Contact Form 7. Bindings work from the page and its requests alone. Class names, actions and addresses here are what current versions use; confirm them on your own site before relying on them.