Cookie preferences

Choose which optional cookies EndFrame may use on this site. Analytics and advertising tools load only if you allow them, and you can change your mind any time from “Cookie settings” in the footer. Whatever you choose, this tab keeps the campaign labels from the link that brought you, and they are saved with your account if you sign up. Read the Cookie Policy.

Needed for the site to work, such as remembering this choice. Always on.

Lets us load analytics tools through Google Tag Manager, including Google Analytics and Microsoft Clarity session recordings, to understand how the site is used.

Allows advertising tags to measure our ad campaigns. None run on this site today. It also keeps ad click IDs from the page address for this tab, and saves them with your account if you sign up.

Skip to main content

Contact Form 7 Conversion Tracking: Use wpcf7mailsent for GA4, Google Ads and Meta

Contact Form 7 submits without reloading the page, so thank-you page and click triggers miss or over-count leads. This guide explains the plugin's five events, which one is a real lead, and how to send it to GA4, Google Ads and Meta, with or without GTM.

The EndFrame Team7 min read

Contact Form 7 sends each submission to WordPress in the background (an Ajax request) and shows its confirmation message under the form without loading a new page. That is why a thank-you page trigger never fires and a click trigger on the send button counts every attempt, including the ones that failed validation. The reliable signal is wpcf7mailsent, a browser event the plugin fires only when the submission is accepted and the email has been sent. Below: how to send it to GA4, Google Ads and the Meta Pixel, with or without Google Tag Manager, and how to test it.

The five Contact Form 7 events and which one is a lead

When the reply from WordPress arrives, Contact Form 7 fires a custom DOM event: a named signal inside the page that your own JavaScript can listen for. The plugin's documentation lists five.

EventWhen it firesUse it as a conversion?
wpcf7submitEvery completed submission, whatever the outcomeNo, it also fires for errors and spam
wpcf7invalidOne or more fields failed validation, so no email was sentNo
wpcf7spamPossible spam was detected, so no email was sentNo
wpcf7mailfailedThe submission was accepted but sending the email failedNo, but worth logging as its own event
wpcf7mailsentThe submission was accepted and the email was sentYes

Many older tutorials listen for wpcf7submit. Because it fires regardless of the result, a visitor who leaves the email field empty, sees the error, fixes it and sends again is recorded as two leads, and blocked spam counts too. wpcf7mailsent matches the email that lands in your inbox. If spam still gets through and inflates that number, see our guide to stopping spam leads from Google Ads.

The events fire on the div with the class wpcf7 that wraps the form, not on the form itself, and they bubble up to the document. A single listener attached to document therefore catches every Contact Form 7 form on the page.

Tell forms apart, and keep personal data out

Each event carries an object called event.detail. The useful properties are detail.contactFormId (the ID of the form), detail.containerPostId (the ID of the page or post the form sits on) and detail.unitTag (an identifier for that instance of the form on the page). Send the form ID with your conversion so a quote request and a newsletter form do not end up as the same lead. To find a form's ID, submit a test and read the value in Tag Manager's preview.

The event also holds detail.inputs, a list of every field the visitor filled in, each with a name and a value. Do not forward names, email addresses, phone numbers or message text to GA4. Google's Analytics policy prohibits sending data Google could recognise as personally identifiable, and free-text fields would create a unique value for almost every lead, which is useless in reports. A non-personal field such as an enquiry type dropdown is fine to send.

Route 1: Google Tag Manager

Use this route if GTM already loads on the site, because one listener feeds every platform. The data layer is a shared list on the page that your code adds messages to and GTM reads from. Our guide to form submission tracking explains why firing on confirmed success beats the alternatives.

  1. 1In GTM, open Tags, click New and choose Custom HTML. Paste this code, wrapped in an opening and closing script tag: document.addEventListener('wpcf7mailsent', function (event) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'cf7_lead', cf7_form_id: event.detail.contactFormId, cf7_event_id: 'cf7-' + Date.now() + '-' + Math.random().toString(36).slice(2) }); }, false);
  2. 2Set that tag to fire on All Pages, or on a Page View trigger limited to the pages that carry a form. Name it CF7 listener.
  3. 3Open Variables, click New under User-Defined Variables and create two Data Layer Variables with the names cf7_form_id and cf7_event_id.
  4. 4Open Triggers, click New and choose Custom Event. Enter cf7_lead as the event name. To track one form only, choose Some Custom Events and add a condition on the cf7_form_id variable.
  5. 5For GA4, create a Google Analytics: GA4 Event tag with your Measurement ID, the event name generate_lead and an event parameter form_id set to the cf7_form_id variable. Fire it on the cf7_lead trigger.
  6. 6For Google Ads, create a Google Ads Conversion Tracking tag. Copy the Conversion ID and Conversion Label from Google Ads (Goals, Conversions, Summary, click the conversion action, then Use Google Tag Manager under Tag setup), put the cf7_event_id variable in Transaction ID so a tag that fires twice for one submission counts once, and use the same trigger.
  7. 7For Meta, if the Pixel base code already loads, add a Custom HTML tag on the same trigger that calls fbq('track', 'Lead', {}, { eventID: '{{cf7_event_id}}' }). GTM replaces the double braces with the variable's value.
  8. 8Click Preview, run the tests described below, then Submit and publish the container.

In GA4, register form_id as an event-scoped custom dimension under Custom definitions so it appears in reports, and mark generate_lead as a key event. Then decide how Google Ads counts it. You can import the GA4 key event into Google Ads or use the Google Ads tag above, but only one of them should be a primary conversion action, the kind Google Ads uses for bidding. Conversion actions created from the Google Analytics side start as secondary, so check the setting under Goals before assuming it is correct. For leads, also set the conversion action's Count option to One. Google's help describes it as the usual choice for leads, because usually only one lead per ad click adds value.

Route 2: without Tag Manager

If GA4 loads through gtag.js directly, for example from Google's Site Kit plugin, Contact Form 7's own documentation shows the approach: add a script to the footer of every page through the wp_footer hook in your theme's functions.php file, with a wpcf7mailsent listener that calls gtag. Its example sends an event called wpcf7_submission with event_category and event_label parameters, which are older Universal Analytics naming. For GA4, use the recommended event name instead.

  • GA4: inside the listener, call gtag('event', 'generate_lead', { form_id: event.detail.contactFormId });
  • Google Ads: copy the event snippet from the conversion action's tag setup in Google Ads and place its gtag('event', 'conversion', { send_to: ... }) call inside the same listener rather than on page load.
  • Meta Pixel: call fbq('track', 'Lead', {}, { eventID: id }) with an ID generated in the listener, so a server-side copy of the same lead can be deduplicated.
  • Placement: put the code in a child theme or a code snippets plugin, not the parent theme's files, so a theme update does not remove it.

This route only works if the gtag and fbq functions exist on the page. If GA4 or the Pixel are loaded through GTM, gtag may not be defined, and Route 1 is the one to use. For installing the Pixel itself, see our guide to adding the Meta Pixel to WordPress.

Turn off GA4 form interactions

GA4 enhanced measurement has an option called Form interactions that sends form_start and form_submit events automatically. Its form_submit reacts to the browser's submit and has no idea whether Contact Form 7 accepted the data, so you would end up with an unreliable form_submit next to your accurate generate_lead. The option is set for the whole web data stream, not per page: go to Admin, Data collection and modification, Data streams, click your web stream, click the settings icon under Enhanced measurement and switch Form interactions off. You need Editor access or higher. Our guide to GA4 enhanced measurement events explains what the other options do.

If your form redirects to a thank-you page

Contact Form 7 keeps visitors on the same page by default, and its author describes redirecting to a thank-you page purely for analytics as unnecessary. Some sites still redirect, usually with a small script that listens for wpcf7mailsent and changes the page address, or with a redirect add-on.

  • If the redirect runs from a wpcf7mailsent script, your tracking listener fires on the same event, but an instant redirect can unload the page before the tags finish sending. The plugin's own redirect example waits three seconds; keep a short delay.
  • If you would rather track the thank-you page view, remember that refreshes, bookmarks and back-button visits all count again unless the platform deduplicates.
  • Pick one method. Tracking both wpcf7mailsent and the thank-you page view records every lead twice.

Test before you trust the numbers

  1. 1Open GTM Preview, or Tag Assistant for a gtag setup, and load the page with the form.
  2. 2Submit with a required field empty. The form shows an error, no cf7_lead event appears and no conversion tag fires.
  3. 3Submit with valid data. Exactly one cf7_lead event appears and the GA4, Google Ads and Meta tags each fire once.
  4. 4In GA4, go to Admin and open DebugView under Data display. generate_lead should appear with the form_id parameter. Events will not show if consent for analytics was not given.
  5. 5In Meta Events Manager, open Data sources, select your dataset, click Test events and open your site from there. Activity is recorded only while that tab is open. One Lead should arrive.
  6. 6After a week, compare conversions per form with the emails received. A small gap from consent and blockers is normal; a gap that grows is a bug.

Our guide to testing tracking with GA4 DebugView covers debug mode in more depth. Before wiring anything, the free pixel inspector lists which pixels and tags appear in the form page's initial HTML, which tells you whether GTM, gtag or the Pixel are already there. It cannot see tags that GTM adds later.

A conversion tells the ad platform that a lead happened, not where it came from. To keep each enquiry's source on the lead itself, add UTM values in hidden form fields. EndFrame can also receive the conversion from the same wpcf7mailsent listener, credit it to the campaign of the visit that converted, and forward it server-side to Meta, GA4 or TikTok. Pass the same event_id and event name you give the Pixel so Meta keeps one copy, and send each conversion to GA4 from one source only, because GA4 does not deduplicate.

Frequently asked questions

Does Contact Form 7 have a built-in Google Analytics integration?

No. The plugin does not send anything to GA4 on its own. Its documentation shows a short script that listens for wpcf7mailsent and calls gtag, and suggests Google's Site Kit plugin as the simplest way to install GA4 itself. Any tracking beyond that comes from code you add or from Google Tag Manager.

Why do I see more leads in Google Ads than emails in my inbox?

The usual causes are a click trigger on the send button, a listener on wpcf7submit instead of wpcf7mailsent, or two tracking methods running side by side, such as an imported GA4 key event and a Google Ads tag both set as primary conversions. Check which events and conversion actions fire for a single test submission.

Will this work if JavaScript is blocked or fails on the page?

No. The DOM events are fired by the plugin's own script after its background submission completes. If that script does not run, the events never fire and no conversion is recorded. Consent settings and ad blockers can also stop GA4, Google Ads or Meta tags even when the event itself fires.

Try EndFrame

Add a server-side path for your conversions.

EndFrame collects events first-party and forwards conversions server-side to Meta, GA4, TikTok, and webhooks with event-ID deduplication — then credits each conversion to its campaign, with the visit-to-conversion path you can audit.

No credit card required

Keep reading