How to Track Contact Form 7 with Google Analytics

Cody Schneider7 min read

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.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

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.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

How It Works:

  1. 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.
  2. 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.

  1. 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.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

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.

  1. In GTM, navigate to Tags > New.
  2. Name the tag something obvious, like cHTML - Contact Form 7 Listener.
  3. Under Tag Configuration, choose Custom HTML.
  4. 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.

  1. Under Triggering, select All Pages, so your listener is active on any page with a contact form.
  2. 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.

  1. In GTM, go to Triggers > New.
  2. Name the trigger Custom - CF7 Form Success.
  3. Under Trigger Configuration, choose Custom Event.
  4. In the Event name field, enter cf7_form_submit. Make sure this matches the event name from the script in Step 1 exactly.
  5. Leave the trigger set to "All Custom Events."
  6. 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.

  1. In GTM, go to Tags > New.
  2. Name the tag GA4 - Event - Lead Generation or similar.
  3. Under Tag Configuration, choose Google Analytics: GA4 Event.
  4. Select your main GA4 Configuration Tag from the dropdown menu.
  5. In the Event Name field, enter a descriptive name in snake_case. For example, generate_lead or contact_submission.
  6. Under Triggering, select the Custom - CF7 Form Success trigger you created in Step 2.
  7. Click Save.

Now, click the Submit button in the top right to publish all your changes.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Verifying It All Works

Don't just assume your setup is working. Use GTM's Preview mode to confirm everything before you walk away.

  1. In your GTM workspace, click the Preview button in the top right.
  2. Enter your website URL and click Connect. A new tab of your website will open with a GTM debug panel.
  3. Navigate to a page with one of your contact forms and submit a test entry.
  4. Watch the debug panel on the left. After a successful submission, you should see the cf7_form_submit event pop up in the event timeline.
  5. Click on that cf7_form_submit event. 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