How to Track Contact Form 7 Submissions as GA4 Key Events
Track Contact Form 7 leads in GA4: listen for wpcf7mailsent, send generate_lead via Tag Manager or gtag, check DebugView, then mark it a key event.
You have a contact form on your site, but you can’t see how many people actually send a message, or which ads and pages brought them. Without that, it’s hard to know what’s working.
This guide shows you how to count successful form sends in Google Analytics 4 (GA4), Google’s free tool for seeing what people do on your site.
In this guide you’ll learn:
- How to listen for a signal called
wpcf7mailsent. That’s Contact Form 7’s way of saying the form was submitted and the email went out. - How to record that as a key event in GA4. A key event is an action you’ve told Google really matters, like a new enquiry.
- How to set this up with Google Tag Manager, or with a short snippet if you don’t use Tag Manager.
- How to check that the count is working, using GA4’s DebugView.
A common mistake is to count every form click, including failed ones, or to wait for a "thank you" page. Contact Form 7 stays on the same page after sending, so those methods miss the mark. This guide uses the signal that only fires when the send really succeeded.
You’ll copy one short snippet. You don’t need to write code. By the end, you’ll be able to see your leads in Analytics, and which channels brought them.
Who this guide is for
- Small business owners who want to see how many enquiries their website generates, and from which channels.
- Marketers running Google Ads or social campaigns who need a lead conversion they can trust.
- WordPress site managers who already use Contact Form 7 and Google Analytics 4.
You’ll copy one short snippet. You don’t need to write code.
What you need before you start
- A WordPress site with Contact Form 7 working. If enquiries aren’t arriving by email, fix that first with our Contact Form 7 email troubleshooting guide.
- A Google Analytics 4 property with a web data stream, and its Measurement ID (it starts with
G-). You’ll find it in Admin → Data collection and modification → Data streams. - For key events: the Editor role (or higher) on the GA4 property to star an existing event, or Marketer (or higher) to pre-create one.
- Method A only: a Google Tag Manager web container already installed on the site, with publish permission.
- Method B only: the GA4 tag (gtag.js) already on the site, for example added by Site Kit or your theme, and a way to add a small code snippet (a must-use plugin or a code-snippets plugin).
- A test email address, and a staging site if you have one.
Contents
- Understand which Contact Form 7 event to track
- Choose your method and event name
- Method A: Track the submission with Google Tag Manager
- Method B: Track the submission with gtag.js (no Tag Manager)
- Check the event arrives in DebugView
- Mark the event as a key event in GA4
- Optional: report on which form was used
- Common errors
- Troubleshooting checklist
- Alternatives and limitations
- FAQ
Step 1: Understand which Contact Form 7 event to track
Contact Form 7 sends small signals in the browser at different points when someone submits a form. These are called JavaScript events, or DOM events — that’s just the browser announcing that something happened. The plugin’s documentation lists these:
| DOM event | When it fires | Use it as a lead conversion? |
|---|---|---|
wpcf7invalid |
The submission finished, but the email wasn’t sent because a field was invalid | No |
wpcf7spam |
The submission finished, but the email wasn’t sent because of suspected spam | No |
wpcf7mailsent |
The submission finished successfully and the email was sent | Yes |
wpcf7mailfailed |
The submission finished, but sending the email failed | No (but useful for alerting) |
wpcf7submit |
The submission finished, whatever the result | No: it also counts failures |
Three details from the documentation matter here:
- These events only fire when the form submits by AJAX, which is the default. If your form reloads the page instead, its JavaScript isn’t loading, and none of this tracking will work until that is fixed.
- Each event bubbles up to
document, so one listener ondocumentcatches every Contact Form 7 form on the page. - The event object carries useful details.
event.detail.contactFormIdis the form’s ID.event.detail.inputscontains everything the visitor typed.
Never send event.detail.inputs to Google Analytics. It contains names, email addresses and messages, and Google’s policies prohibit sending personally identifiable information (PII) to Analytics. The snippets in this guide send only the form ID.
Step 2: Choose your method and event name
Pick a method:
| If your site… | Use |
|---|---|
| Already loads GA4 through Google Tag Manager | Method A (Step 3) |
| Loads GA4 directly with gtag.js (Site Kit, theme setting or header snippet) and has no Tag Manager | Method B (Step 4) |
| Uses both | Method A only. Don’t run both methods, or every lead is counted twice. |
Pick an event name. We recommend GA4’s recommended event generate_lead. Google defines it for exactly this purpose (a lead submitted through a form or request for information), and its parameters include value, currency and the optional lead_source. Google’s notes for this event say value is recommended if you mark it as a key event, and that currency is required whenever you set value.
If you already use generate_lead for something else, choose a custom name such as contact_form_lead. Keep it under GA4’s 40-character limit for event names, use lowercase letters and underscores, and use exactly the same name everywhere. GA4 treats Generate_Lead and generate_lead as different events.
Optional lead value. If you know roughly what an enquiry is worth (for example, 10% of enquiries become RM 2,000 jobs, so each lead is worth about RM 200), you can send value: 200 and currency: 'MYR'. If you don’t know, leave both out. A made-up value distorts any ROAS figures built on it.
Step 3: Method A: Track the submission with Google Tag Manager
You’ll create four things in your GTM web container: a listener tag, a trigger, a variable, and a GA4 Event tag. Menu names can vary by Tag Manager version; follow the current labels if they differ from the names below.
3a. Add the listener tag
-
In Tag Manager, open your container and go to Tags → New.
-
Name it
CF7 – mailsent listener. -
Choose Tag Configuration → Custom HTML and paste:
<script> document.addEventListener('wpcf7mailsent', function (event) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'cf7_mail_sent', cf7_form_id: String(event.detail.contactFormId) }); }, false); </script> -
Under Triggering, choose a page-view trigger that fires on pages with your forms. All Pages is simplest.
-
Save.
This tag adds a listener. When Contact Form 7 reports a successful send, the listener pushes a cf7_mail_sent event into the data layer with the form ID, and nothing else.
3b. Create the trigger
- Go to Triggers → New → Trigger Configuration → Custom Event.
- Event name:
cf7_mail_sent. Leave "Use regex matching" off, and match the name exactly, including case. - This trigger fires on: All Custom Events.
- Name it
CE – cf7_mail_sentand save.
3c. Create the form ID variable
- Go to Variables → User-Defined Variables → New → Data Layer Variable.
- Data Layer Variable Name:
cf7_form_id. - Name it
DLV – cf7_form_idand save.
3d. Create the GA4 Event tag
- Go to Tags → New → Google Analytics → Google Analytics: GA4 Event.
- Enter your Measurement ID (
G-...), or select the Google tag your container already uses. - Event Name:
generate_lead(or the custom name you chose). - Under Event Parameters, add
form_idwith the value{{DLV – cf7_form_id}}. Optionally addvalueandcurrency(see Step 2). - Triggering:
CE – cf7_mail_sent. - Save.
3e. Preview, then publish
- Click Preview, enter your page URL, and submit a real test through the form.
- In the Tag Assistant window, you should see a
cf7_mail_sentevent in the left-hand timeline, with your GA4 Event tag listed under Tags Fired for it. - Submit an invalid test as well, for example with the email field empty. No
cf7_mail_sentevent should appear for that attempt. - When both checks pass, click Submit → Publish in Tag Manager.
The expected Tag Assistant results above follow from the documentation and the listener logic test, not from a live container we observed.
Step 4: Method B: Track the submission with gtag.js (no Tag Manager)
Use this only if GA4 is already loaded on the page with gtag.js and you’re not using Method A.
-
Confirm that gtag is present. Open a page with your form, open the browser’s developer console (F12), type
typeof gtagand press Enter. If it prints"function", continue. If it prints"undefined", GA4 isn’t loaded with gtag.js on that page, so use Method A or install GA4 first. -
Add the listener to every page that has a form. The cleanest way that survives theme updates is a must-use plugin:
- Using SFTP or your host’s file manager, go to
wp-content/. Create a folder namedmu-pluginsif there isn’t one already. - Create the file
wp-content/mu-plugins/cc-cf7-ga4-lead.phpwith this content:
<?php /** * Plugin Name: ConvertCortex – CF7 to GA4 generate_lead * Description: Sends a GA4 generate_lead event when Contact Form 7 reports a successful send. */ add_action( 'wp_footer', function () { ?> <script> document.addEventListener('wpcf7mailsent', function (event) { if (typeof gtag !== 'function') { return; } gtag('event', 'generate_lead', { form_id: String(event.detail.contactFormId) }); }, false); </script> <?php }, 100 ); - Using SFTP or your host’s file manager, go to
-
Clear any page cache or optimisation plugin cache, then submit a test.
The snippet uses WordPress’s wp_footer action, which outputs content in the page footer, so it runs on every front-end page. If you’d rather not upload files, paste only the <script>…</script> part into a code-snippets plugin set to load in the site footer. We haven’t run this must-use plugin on a live WordPress install. Back up first and test it on a staging site.
Step 5: Check the event arrives in DebugView
GA4’s standard reports can take up to 24 hours to show new events, so check with DebugView, which shows events in seconds.
- Turn on debug mode for your browser. The simplest way is to start a Tag Assistant session (tagassistant.google.com), or GTM Preview for Method A. With gtag.js you can instead add
'debug_mode': trueto your config, but remove it afterwards: setting it tofalsedoesn’t turn debug mode off, you have to delete the parameter. - In GA4, go to Admin → Data display → DebugView.
- Submit a successful test through your form.
- Within a few seconds,
generate_leadshould appear in the seconds stream. Click it and confirmform_idholds your form’s ID. - Then submit an invalid test and confirm that no extra
generate_leadappears.
If your site uses a cookie banner with Google consent mode, Google notes that events won’t appear in DebugView until consent is granted. Accept analytics cookies in your test browser.
Step 6: Mark the event as a key event in GA4
"Key events" is GA4’s name for what used to be called conversions. Once the event is in your property:
- In GA4, go to Admin → Data display → Events. You need the Editor role or higher.
- Find
generate_leadin the list. A new event can take a while to appear here. - Click the star icon in its row to mark it as a key event.
If the event isn’t listed yet: Google says new events may take a while to appear, but you can mark them as key events ahead of time. On the same Events screen, click + Create event (Marketer role or higher), enter the exact event name generate_lead, switch on Mark as key event, choose the default value and counting method, and click Create. Special characters can’t be used in the name.
Points to know, from Google’s key events documentation:
- A standard GA4 property can have up to 30 key events (50 on Analytics 360).
- Key events can take up to 24 hours to appear in standard reports. Realtime shows them within minutes.
- Marking an event as a key event affects reports from that point on. It doesn’t change historic data.
- You can set a counting method and a default value for the key event. Google recommends "Once per event" as the counting method.
Exact menu path: verified from Google’s help page on 12 November 2026. Google renames GA4 menus from time to time. If yours differs, search the Admin page for "Events".
Step 7: Optional: report on which form was used
If you have several forms (for example "Contact" and "Request a quote"), you can break down leads by form ID:
- In GA4 Admin, open the Custom definitions page and create a new custom dimension. Exact button label: to be confirmed on the test property.
- Scope: Event. Event parameter:
form_id. Dimension name: for example "CF7 form ID". - Save. Google says it can take 24 to 48 hours before you can report on a new custom dimension.
To find a form’s ID, go to Contact → Contact Forms in WordPress. The ID appears in each form’s shortcode, for example [contact-form-7 id="..." title="Contact form 1"]. Some versions show a hash-style ID in the shortcode instead. If so, check event.detail.contactFormId in your DebugView test to see exactly which value is sent.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| No event at all | The form isn’t submitting by AJAX (the page reloads), or a JavaScript error stops scripts running | See our Contact Form 7 not-submitting guide. Check the browser console for errors. |
| Event fires twice per submission | Both Method A and Method B are active, or the listener tag fires on two triggers | Keep one method. Make sure the listener tag has a single page-view trigger. |
| Event fires for failed or spam submissions | You listened to wpcf7submit instead of wpcf7mailsent |
Use wpcf7mailsent |
| Leads counted twice in GA4 | Enhanced measurement’s form_submit is also marked as a key event |
Mark only generate_lead as a key event (see Alternatives) |
generate_lead in DebugView but not in reports |
Reports lag up to 24 hours | Wait. Use Realtime to confirm in the meantime. |
Generate_lead and generate_lead both appear |
Event names are case-sensitive | Pick one spelling and fix every tag |
| Email addresses visible in GA4 | detail.inputs or a field value was sent as a parameter |
Remove it immediately, and follow Google’s PII guidance on deleting the data |
gtag is not defined in the console |
GA4 isn’t loaded via gtag.js, or loads after your listener | Method B’s typeof check fails silently in this case. Use Method A, or fix the GA4 install. |
If the form itself never submits, or the spinner keeps spinning, that’s a different problem. See our Contact Form 7 not-submitting guide.
Troubleshooting checklist
- Does the form submit without reloading? If the URL changes to something like
#wpcf7-f123-o1, AJAX isn’t running and DOM events won’t fire. - Do you get the green "Thank you" message?
wpcf7mailsentonly fires on a successful send. If you see a red or orange border, fix email sending first. - Is the listener on the page? View the page source, or check GTM Preview to see that
CF7 – mailsent listenerfired on page view. - Is a cache or "delay JavaScript" optimisation holding the script back? Exclude the snippet, or clear the cache and retest.
- Does the data-layer event name match the trigger exactly?
cf7_mail_sentis not the same ascf7_mailsent. - Is the GTM container published? Preview mode only affects your own browser.
- Is consent mode blocking analytics in your test browser? Accept analytics cookies and retest.
- Is the GA4 Measurement ID the right one? Check the ID on the tag against Admin → Data streams.
Alternatives and limitations
- GA4 enhanced measurement "Form interactions". It can automatically collect
form_startandform_submit, with parameters such asform_id(the form’s HTML id) andform_destination. Google describesform_submitsimply as "when the user submits a form". It doesn’t say anything about whether the email was sent, so it’s not a reliable lead count for Contact Form 7. Don’t markform_submitas a key event alongsidegenerate_lead, or you’ll double-count. You can switch Form interactions off in the web data stream’s enhanced measurement settings. We have not confirmed exactly whenform_submitfires with a Contact Form 7 form (for example on a failed validation). - Thank-you page redirect. Redirecting to
/thank-you/and tracking that page view works, but Contact Form 7 doesn’t redirect by default. Adding a redirect means extra code or a plugin, and visitors can reach the URL directly, which inflates counts. - Plugins that connect forms to GA4. Some tracking plugins offer this. They’re fine if you prefer a settings screen, but check what data they send. We don’t recommend a specific one and have no affiliate relationships.
- Server-side tracking. It’s more robust against ad blockers, but needs a server container or the Measurement Protocol, which is beyond this guide.
- Limitations: ad blockers and declined consent mean GA4 will always record fewer leads than your inbox receives. Treat GA4 as a trend and attribution tool, and Flamingo or your inbox as the true lead count.
FAQ
Is a key event the same as a conversion?
Google renamed GA4’s "conversions" to "key events". A "conversion" now means a Google Ads conversion, which you can create from a GA4 key event so you can use it for ad reporting and bidding.
Should I use generate_lead or a custom event name?
Use generate_lead unless you already use it for something else. It’s a recommended event, so GA4 and Google Ads understand what it represents.
Can I track which page the form was on?
GA4 already records the page location with every event, so you don’t need to send it yourself.
Will this count spam submissions?
Not if Contact Form 7’s spam protection catches them, because spam fires wpcf7spam, not wpcf7mailsent. Spam that gets through and is "sent" will be counted.
Can I send the visitor’s email address to GA4 for matching?
No. Google’s policies prohibit sending PII to Analytics. Use Google’s approved features (for example, user-provided data collection) only after reviewing the requirements and your privacy policy.
Does this work with Contact Form 7 multi-step or redirect add-ons?
Not verified. Add-ons can change how submissions complete, so test with your exact setup.
Official references
- Contact Form 7: DOM events
- Google Analytics Help: Mark events as key events, How to measure key events, Conversions vs. key events, Monitor events in DebugView, Enhanced event measurement, About custom dimensions and metrics, Event collection limits, Best practices to avoid sending PII
- Google for Developers: Recommended events: generate_lead
- Tag Manager Help: Custom event trigger, GA4 Event tag, User-defined variable types, Preview and debug containers
- WordPress Developer Resources: wp_footer hook
Next step
Once leads are tracked, make sure GA4 and Search Console are connected so you can see which search queries bring enquiries. If emails from the form still go missing, start with our Contact Form 7 email guide.
Last updated: 13 November 2026



