A contact form submission is often the most valuable action on a small business website. But Contact Form 7 sends forms without reloading the page, so there is no “thank you” URL to track. Here is how to measure every successful submission in Google Analytics 4.
This guide assumes GA4 is already installed. If not, start with how to add Google Analytics 4 to WordPress.
The event to listen for
Contact Form 7 fires JavaScript events on the form. The ones that matter here:
wpcf7submit: the form was submitted, even if a field was invalid.wpcf7mailsent: the message was sent successfully.wpcf7mailfailed: the message could not be sent.
Track wpcf7mailsent. It only fires when a lead really reaches you.
Step 1: send the event to the data layer
Add this listener to your site, for example with the wp_footer hook in your child theme:
<script>
document.addEventListener( 'wpcf7mailsent', function ( event ) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push( {
event: 'cf7_submit_success',
form_id: event.detail.contactFormId
} );
} );
</script>
Step 2: create the trigger in Tag Manager
Create a trigger of type Custom Event with the event name cf7_submit_success. Then create a Data Layer Variable named form_id, so you can tell your forms apart.
Step 3: create the GA4 event tag
Create a tag of type Google Analytics: GA4 Event:
- Measurement ID: your
G-XXXXXXXXXX. - Event name:
generate_lead, Google’s recommended name for lead forms. - Event parameter:
form_idwith the value of yourform_idvariable. - Trigger:
cf7_submit_success.
Test it in Preview, then publish the container.
Using the native Google tag instead
Without Tag Manager, send the event directly inside the same listener:
gtag( 'event', 'generate_lead', { form_id: event.detail.contactFormId } );
Step 4: mark it as a key event
In Google Analytics, go to Admin › Data display › Events and turn on Mark as key event for generate_lead. If the event has not arrived yet, create it in Key events › New key event with exactly the same name.
Check that it works
- Open your site in Tag Manager Preview and send a test message.
- Confirm that the GA4 event tag fired once.
- Look for
generate_leadin DebugView or Realtime.
Common mistakes
- Tracking
wpcf7submit, which also counts forms with errors. - Tracking clicks on the submit button instead of sent messages.
- Sending the event from both the native tag and Tag Manager, which doubles every lead.
- Sending names, emails or phone numbers to Google Analytics. Its policies don’t allow personal information.
If you want me to set up conversion tracking on your site, get in touch. You can also browse my portfolio or read more about me.