How to Track Contact Form 7 with Google Analytics
Tracking submissions from your Contact Form 7 form is one of the most enlightening experiences you can have as a marketer. Your forms may feel like a black box, a user fills one out, you get an email notification, and that's it. By connecting it to Google Analytics, you can finally see which marketing channels, campaigns, and pages are actually generating valuable leads for your business. This article will show you exactly how to set up conversion tracking for Contact Form 7 in Google Analytics 4.
Why Bother Tracking Form Submissions?
Setting up form tracking is the first step toward understanding your website’s performance and calculating your return on investment. Once an essential website interaction like a form submission is measured in Google Analytics, you can answer critical business questions like:
- Which blog post generates the most contact inquiries?
- How much did that new Google Ads campaign contribute to our leads this month?
- What is the conversion rate of visitors who land on our services page?
- Are visitors on mobile devices submitting forms, or are they experiencing issues?
Without this data, you're just guessing. With it, you can make informed decisions to double down on what’s working and fix what isn’t.
The Old Method: Thank You Page Redirect
One of the simplest ways to track form submissions has always been a "Thank You" page redirect. The logic is straightforward: if a user lands on your thank-you page, they must have successfully submitted a form.
How It Works:
- Create a "Thank You" Page: In WordPress, create a new page (e.g., yourwebsite.com/thank-you). Add a welcoming message confirming the submission was received. Most importantly, set this page to "noindex" in your SEO plugin settings to prevent organic traffic from finding it and skewing your conversion data.
- Redirect the Form: This feature is no longer built directly into Contact Form 7's UI, so you'll need a bit of code. Add the following script to your website. Many themes have a spot for custom scripts, or you can use a plugin like "Insert Headers and Footers."
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://yourwebsite.com/thank-you/',
}, false ),
</script>Just remember to replace http://yourwebsite.com/thank-you/ with your actual URL.
- Create a GA4 Event: In Google Analytics 4, go to Admin > Events and click "Create event." Name your event (e.g., contact_form_submission), and set the matching condition to page_location equals http://yourwebsite.com/thank-you/.
Why This Method Isn't Ideal
While simple, this approach has drawbacks. The redirect can feel clunky for user experience, and it doesn't always track accurately if a user closes the tab before the redirect completes. More importantly, you lose the context of which specific form was submitted on which page. It's an okay start, but there is a much more modern and reliable way.
The Modern & Recommended Method: Using DOM Events
Contact Form 7 actively communicates what's happening by broadcasting JavaScript "DOM events." Think of the form shouting out announcements like "I was just submitted successfully!" or "Someone tried to send spam!" We can listen for these specific announcements and use them to trigger a Google Analytics event tag.
Here are the primary events Contact Form 7 sends out:
wpcf7invalid: A user submitted the form, but it had validation errors (e.g., a required field was empty).wpcf7spam: The form submission was flagged as spam.wpcf7mailsent: The form was submitted successfully, and the email was sent. This is the event we want to track.wpcf7mailfailed: The form was submitted successfully, but the email failed to send.
Using Google Tag Manager (GTM) is the professional standard for this method. It keeps tracking scripts separate from your website's code, making things cleaner, safer, and easier to manage.
Step-by-Step: Tracking with Google Tag Manager
If you haven't already, make sure you have Google Tag Manager installed on your WordPress site and your GTM container is connected to your GA4 property. Once that's ready, follow these three steps.
Step 1: Create a Custom HTML "Listener" Tag
First, we need to create a tag whose only job is to "listen" for the wpcf7mailsent event. When it hears it, it will pass a custom event into GTM's data layer - a sort of messaging system that lets your website talk to GTM.
- In GTM, navigate to Tags > New.
- Name the tag something obvious, like
cHTML - Contact Form 7 Listener. - Under Tag Configuration, choose Custom HTML.
- Paste the following code into the HTML box:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
window.dataLayer.push({
"event": "cf7_form_submit",
"formId": event.detail.contactFormId,
"response": event.detail.inputs
}),
}),
</script>This code listens for that successful submission and pushes an event to the data layer called cf7_form_submit. It also includes helpful data like the specific form ID.
- Under Triggering, select All Pages, so your listener is active on any page with a contact form.
- Click Save.
Step 2: Create a Custom Event Trigger
Next, we need to create a trigger that fires whenever that cf7_form_submit event appears in the data layer. This is how we’ll activate our GA4 tag in the next step.
- In GTM, go to Triggers > New.
- Name the trigger
Custom - CF7 Form Success. - Under Trigger Configuration, choose Custom Event.
- In the Event name field, enter
cf7_form_submit. Make sure this matches the event name from the script in Step 1 exactly. - Leave the trigger set to "All Custom Events."
- Click Save.
Step 3: Create the Google Analytics 4 Event Tag
Finally, we'll create the GA4 tag that sends the information to Google Analytics every time the trigger from Step 2 is activated.
- In GTM, go to Tags > New.
- Name the tag
GA4 - Event - Lead Generationor similar. - Under Tag Configuration, choose Google Analytics: GA4 Event.
- Select your main GA4 Configuration Tag from the dropdown menu.
- In the Event Name field, enter a descriptive name in snake_case. For example,
generate_leadorcontact_submission. - Under Triggering, select the Custom - CF7 Form Success trigger you created in Step 2.
- Click Save.
Now, click the Submit button in the top right to publish all your changes.
Verifying It All Works
Don't just assume your setup is working. Use GTM's Preview mode to confirm everything before you walk away.
- In your GTM workspace, click the Preview button in the top right.
- Enter your website URL and click Connect. A new tab of your website will open with a GTM debug panel.
- Navigate to a page with one of your contact forms and submit a test entry.
- Watch the debug panel on the left. After a successful submission, you should see the
cf7_form_submitevent pop up in the event timeline. - Click on that
cf7_form_submitevent. You should see that your GA4 - Event - Lead Generation tag successfully fired.
You can also check the Realtime report in Google Analytics or, for more detail, navigate to Admin > DebugView. Here, you should see your generate_lead event appear a few seconds after your test submission.
Final Thoughts
Getting your form submission data into Google Analytics is a powerful upgrade, turning a simple contact form into a measurable cornerstone of your marketing strategy. By using Google Tag Manager and the built-in DOM events, you can create a reliable, scalable tracking system that provides the insights you need to grow your business.
Setting up tracking is a powerful first step, but it's just one piece of a much larger data puzzle. This is exactly why we built Graphed. We got tired of spending hours connecting data points from different platforms just to understand what was really working. Graphed connects your core marketing and sales tools - like Google Analytics, Google Ads, Shopify, and your CRM - so you can skip the manual setup and simply ask for what you need. Instead of hunting through GA4 reports, you can just ask, "Show me how many leads we generated from our blog last quarter," and get an instant dashboard visualizing your performance.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.