Contact Form 7 Event Listener: Track Real Submissions

Contact Form 7 fires a DOM event only when the mail actually sends. Here is how to turn that into a clean conversion in GA4, Google Ads and Meta.

Contact Form 7 has one genuinely good feature for tracking: it fires a different event depending on whether the email actually sent. Most form plugins do not make that distinction, and it is the difference between counting leads and counting attempts.

This post shows you how to catch that event and turn it into a conversion in GA4, Google Ads and Meta.

Why you need a listener

Contact Form 7 submits over AJAX. No page reload, no thank you page, no URL change. Page based tracking sees nothing.

What it does do is dispatch DOM events on the document. The important one is wpcf7mailsent, which fires only when the mail was successfully sent. There is also wpcf7invalid for validation failures and wpcf7mailfailed for send failures, which you do not want to count.

The listener code

This is the Contact Form 7 listener from DumbData.

The full listener is in the copy block at the bottom of this page, with a copy button. It is reproduced exactly as DumbData publish it, so you can copy it straight from here or from their page.

It listens for wpcf7mailsent and pushes an event called cf7submission, along with the form ID and the submitted inputs.

Installing it in GTM

  1. Create a Custom HTML tag in Google Tag Manager and paste the listener.

  2. Trigger it on All Pages, or limit it to the pages that contain the form.

  3. Save and open Preview.

Creating the trigger

  1. New trigger, type Custom Event.

  2. Event name: cf7submission

  3. Leave it on All Custom Events unless you want to split by form.

  4. Save it as CE CF7 Submission.

Creating Data Layer Variables

Two are worth having:

  1. Data Layer Variable named formId. Call it DLV CF7 Form ID.

  2. Data Layer Variable named response. Call it DLV CF7 Response.

formId is the numeric Contact Form 7 ID, which you can see in the plugin’s form list. Write down which ID is which form somewhere, because a bare number in a report tells nobody anything.

Sending it to GA4

  1. Create a GA4 Event tag.

  2. Event name: generate_lead

  3. Add a form_id parameter from your Data Layer Variable.

  4. Trigger: CE CF7 Submission.

Use one event name across every form and separate them with parameters. Six differently named events are much harder to report on than one event with a form_id.

Sending conversions to Google Ads

  1. Create a conversion action in Google Ads and note the ID and label.

  2. Add a Google Ads Conversion Tracking tag in GTM with those values.

  3. Trigger: CE CF7 Submission.

  4. Turn on Enhanced Conversions if the form collects an email: Enhanced Conversions setup

Meta and everything else

Same trigger, different tag. A Meta Pixel tag with the Lead event, a Mixpanel or Piwik PRO tag from their GTM template, a LinkedIn or Microsoft conversion tag. You write the listener once and every platform reads from the same event.

Using the response data

The response value is an array of the submitted fields. It is useful and it contains whatever people typed, so treat it as personal data.

Reasonable uses: pulling the email for Enhanced Conversions or Meta matching, or reading a non personal dropdown such as enquiry type and sending that as a GA4 parameter.

Not reasonable: pushing names, emails or message text into analytics.

Testing

  1. Open GTM Preview on a page with the form.

  2. Submit it properly and wait for the green success message.

  3. Confirm cf7submission appears in the event stream.

  4. Check the Data Layer tab for formId.

  5. Submit an invalid form and confirm nothing fires.

That last test is the one worth doing. If a failed submission fires your conversion, you are inflating your lead count.

Common issues

  • Nothing fires. Check the form is really Contact Form 7 and not another plugin using similar markup.

  • It fires on failures. You are listening for wpcf7submit rather than wpcf7mailsent. Use the listener above.

  • It fires twice. The listener is installed in GTM and also hardcoded in the theme or a plugin.

  • formId is undefined. The variable name must be exactly formId, with that capitalisation.

Privacy considerations

  • Never send names, emails, phone numbers or free text into GA4. It breaches Google’s terms and it is the most common way personal data ends up where it should not be.

  • Hash anything you send to an ad platform for matching.

  • Gate the tags behind marketing consent in your consent tool: Consent Mode v2 in GTM

Final thoughts

Contact Form 7 is one of the easier platforms to track properly, because the plugin already tells you the difference between sent and failed. Use wpcf7mailsent and you get a clean conversion with no extra work.

Listener maintained by DumbData. Their full listener library covers most other tools you are likely to hit.

Need this built properly?

A conversion should mean the email arrived, not that someone pressed a button. I set up and repair tracking for ecommerce stores and lead generation businesses, so the numbers in your ad accounts match the money in your bank account.

Have a look at what I do, or book a call and we can go through your setup together.

Event listener code
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
window.dataLayer.push({
"event" : "cf7submission",
"formId" : event.detail.contactFormId,
"response" : event.detail.inputs
})
}); 
</script>

Need accurate tracking?

Its Free

500+ Happy Clients ⭐️

Keep Reading

See exactly where you’re wasting ad spend and how better tracking can double your sales.

See exactly where you’re wasting ad spend and how better tracking can double your sales.

Tracking in 3 Hours

Tracking in 3 Hours

I Manage Everything

I Manage Everything

24/7 Expert Support

24/7 Expert Support

TESTIMONIALS

Trusted by 500+ satisfied clients

Discover how we’ve driven growth and innovation.

500+ Tracking

500+ Tracking

Adélaïde De Vos

3,922 followers

I had the pleasure to work with Abdul and I can say that he exceeded my expectations. He was professional, patient, and clear in his explanations and committed to client satisfaction. If you're looking for someone who is not only highly skilled but also reliable and committed to client satisfaction, I highly recommend Kayium!

Dean Watson

1,030 followers

Kayium setup our tracking for Google Ads and Meta Ads, which helped us get 20%+ more conversions on the same ad spend. He didn’t just handle the technical setup,he also took the time to explain why it works and how it improves results. If you’re looking for someone skilled, reliable, and committed to delivering real results, I highly recommend him!

David Friend

CEO: Profitable Sites

Kayium set up accurate tracking that helped us scale ads fast and boost conversions by over 25%. He gave us clear insight into which ads drive revenue.

Lalita Sundari

7,924 followers

I've worked with Kayium; his strategic mindset and expertise in GTM, GA4, Pixel & Server Side Tracking, are invaluable! I highly recommend Kayium!