How to Track Form Submissions with GTM and GA4

How to Track Form Submissions with GTM and GA4

Tracking form submissions is one of the most common requirements in web analytics. This guide covers multiple approaches, because the right method depends on how your form works. Follow along, and you will have a reliable setup by the end.

TL;DR – Quick Summary

  • Thank-you page redirects: Track the page view
  • AJAX forms: Use dataLayer.push() after successful submission
  • No code access: Use Element Visibility trigger for success message
  • Always test in GTM Preview mode and GA4 DebugView

What You Will Learn

  1. Different ways forms can behave (and why it matters)
  2. How to track forms that redirect to a thank-you page
  3. How to track AJAX forms that do not reload
  4. How to verify your tracking works

Why Form Tracking Matters

Forms are often the most important conversion points on a website: contact requests, newsletter signups, quote requests, registrations. If you do not track them, you cannot measure what drives conversions.

GA4 Enhanced Measurement can track some form submissions automatically, but it is not reliable for all forms. That is why manual implementation is often necessary.

First, Understand Your Form

Before you implement tracking, you need to know how your form behaves after submission:

  • Redirect to thank-you page: The browser navigates to a new URL after submission
  • AJAX submission: The form submits without page reload, showing a success message
  • Same-page reload: The page reloads and shows a confirmation

Each scenario requires a different tracking approach.

Method 1: Track the Thank-You Page

If your form redirects to a thank-you page, this is the simplest approach.

Step 1: Create a Page View Trigger

  1. Go to GTM → Triggers → New
  2. Choose Page View
  3. Select “Some Page Views”
  4. Set the condition: Page Path contains /thank-you (adjust to your URL)
  5. Save the trigger

Step 2: Create a GA4 Event Tag

  1. Go to GTM → Tags → New
  2. Choose GA4 Event
  3. Select your GA4 Configuration tag
  4. Set event name to generate_lead (or your preferred name)
  5. Attach the thank-you page trigger
  6. Save

This method tracks page views, not actual submissions. If someone bookmarks the thank-you page and visits it later, it will count as a conversion. For most cases, this is acceptable.

Method 2: Track AJAX Form Submissions

If your form submits via AJAX and shows a success message without reloading, you need a different approach.

Option A: Data Layer Push (Recommended)

This is the most reliable method because it fires only after a successful submission. Ask your developer to implement it.

Ask your developer to push an event when the form submits successfully:

// After successful form submission
dataLayer.push({
  event: "form_submit",
  form_name: "contact_form",
  form_location: "homepage"
});

Then in GTM:

  1. Create a Custom Event trigger for form_submit
  2. Create a GA4 Event tag with event name generate_lead
  3. Add parameters for form_name and form_location if needed

Option B: Element Visibility Trigger

If you cannot modify the code, you can track when a success message appears:

  1. Go to GTM → Triggers → New
  2. Choose Element Visibility
  3. Set Selection Method to CSS Selector
  4. Enter the selector for your success message (e.g., .form-success-message)
  5. Check “Observe DOM changes”
  6. Save

This method depends on the DOM structure. If the success message markup changes, the trigger will break. Document the selector you use.

Option C: Form Submission Trigger

GTM has a built-in Form Submission trigger, but it has limitations:

  • It fires when the form submits, not when submission succeeds
  • It may not work with AJAX forms
  • It can fire even if validation fails

If you use this method, enable “Check Validation” to reduce false positives. But be aware: this checks browser validation, not server-side validation.

Adding Event Parameters

To make your data more useful, add parameters to identify which form was submitted:

  1. In your GA4 Event tag, expand “Event Parameters”
  2. Add a parameter: form_name with value from your data layer variable or a constant
  3. Add form_location to track where the form appears

Testing Your Implementation

Do not publish without testing. Follow this sequence to verify everything works correctly.

  1. GTM Preview mode: Submit a test form. Confirm the trigger fires and the tag executes.
  2. Check the data layer: In Preview mode, click on your event and verify the data layer values.
  3. GA4 DebugView: Go to GA4 → Admin → DebugView. Find your event and check parameters.
  4. Wait for Realtime: After a few minutes, check Realtime reports to confirm events arrive.

If you do not see the event in GA4, but the tag fires in GTM, check your Measurement ID. If the tag does not fire, review your trigger conditions.

Decision Tree: Which Method to Use

  • If your form redirects to a thank-you page → Track the page view
  • If your form uses AJAX and you can modify code → Use data layer push
  • If your form uses AJAX and you cannot modify code → Use Element Visibility trigger
  • If nothing else works → Try the Form Submission trigger with validation

Common Mistakes

Avoid these common pitfalls:
  • Tracking form submit instead of successful submission (counts failed attempts)
  • Not accounting for multiple forms on the same page
  • Using Form Submission trigger for AJAX forms (often does not work)
  • Forgetting to test with actual form submissions

Wrap-Up

Form tracking depends on how your form works. For redirects, track the thank-you page. For AJAX forms, use data layer pushes or element visibility. Always test in Preview mode and verify in DebugView before publishing. Once your form tracking works, you can finally measure which channels and pages drive conversions.

Julius
Written by

Julius

Web Analytics Consultant

I help businesses understand their data through proper analytics implementation. With years of experience in Google Analytics, Tag Manager, and tracking solutions, I write practical guides that focus on real-world implementation.

Need Help With Your Analytics Setup?

Whether you are implementing GA4, setting up consent management, or building custom tracking solutions, I can help you get it right the first time.