Skip to main content

Forms, Leads and GA4 Reporting · Part 1: Form and lead tracking

Chapter 8.1 · 1 of 36 · 4 min

Three ways to capture a form submission: URL, GTM trigger, element visibility

There are three ways, and each has a different level of reliability.

Free to read

There are three ways, and each has a different level of reliability.

Way one: the thank you URL

If the site takes the user to a separate page after the form is submitted, such as /thank-you/ or /contact-success/, the job is at its cleanest. When that page loads, that is the conversion.

In GTM, a Page View trigger with the condition Page Path contains /thank-you.

The advantage of this approach: only a successful submission reaches that page. A failed submission stays on the form page.

This approach has one risk, and it is a big one. People can bookmark the URL, share it and refresh it. In one client's account I found 340 lead conversions, 90 of which came from the same IP, because their sales team used the thank you page as an internal shortcut.

Way two: GTM's built-in triggers

GTM has two ready-made triggers for this: Form Submission and Click.

The Form Submission trigger is tied to the browser's own submit event. If an HTML form submits in the standard way, it works.

The problem: most forms today do not submit in the standard way. They send data with AJAX, so the page does not reload, and the browser's submit event is either blocked or never happens at all.

So I do not use GTM's Form Submission trigger as my first choice on a client's site. I test first, then decide.

The Click trigger is even more dangerous. A click on the submit button does not mean the form was submitted. The click happens even when the email field is empty, and your conversion gets counted.

Way three: element visibility

This is my main approach for AJAX forms: capture the success message that appears on the page after the form is submitted.

In GTM, use an Element Visibility trigger. Set Selection Method to CSS Selector, put the success message container in the selector, and set When to fire this trigger to Once per page.

For older Contact Form 7 versions (before 5.2), the success message selector is .wpcf7-response-output.wpcf7-mail-sent-ok. The last class is essential. .wpcf7-response-output on its own is also present during a validation error, so if you target that, failed submissions get counted too. From CF7 5.2 onwards, that class no longer exists: the status sits on the form element instead, so the equivalent selector is .wpcf7 form.sent .wpcf7-response-output. On any current CF7 site, the wpcf7mailsent event in the next chapter is the better signal anyway.

javascript
// Run this in the Console to check whether the selector actually matches anything.
// If you get 0, the selector is wrong, or the message has not appeared on screen yet.
document.querySelectorAll('.wpcf7-response-output.wpcf7-mail-sent-ok').length;

On CF7 5.2 or later, run the same check with .wpcf7 form.sent .wpcf7-response-output in place of the selector above.

Element Visibility has one limit: the element must be visible in the viewport. If the success message appears far down the page and the user does not scroll, the trigger will not fire. Lowering Minimum Percent Visible to 1 percent reduces this a lot, but does not remove it entirely.

Which way, and when

My own order of preference: if the plugin pushes its own dataLayer event, I use that. If not, the thank you URL. If there is none, Element Visibility on the success message. Last of all, the Form Submission trigger, and never the Click trigger.

Steps

  1. Submit the form on your own site once with valid details. Check whether the URL changes.
  2. If the URL does not change, right-click the success message and choose Inspect. Note its class and id.
  3. Run the querySelectorAll line above in the Console with your own selector. The result must be 1.
  4. Now submit the form empty. While the validation error is showing, run the same selector. This time the result must be 0.
  5. In GTM, create an Element Visibility trigger, Once per page, Minimum Percent Visible 1.

What not to do

  • Do not set up a lead conversion with a Click trigger on the submit button. This is the most common mistake I see, and it is the one that creates the most junk conversions in a client's Ads account.
  • Do not choose Every time instead of Once per page in Element Visibility. If the success message comes into view repeatedly as the user scrolls, it will be counted each time.
  • Do not rely on the thank you URL if the client's team opens that URL by hand. Ask them, at least once.

Proof

In Preview mode, submitting the form with valid details fires your trigger, and submitting it empty does not fire it during the validation error. You have seen both with your own eyes.

Want the full chapter list, or to jump to another chapter?

All chapters in the book