The original article was written on May 28, 2019, and it focused on sending data to Google Analytics Universal. However, during the migration of the blog to a new CMS, I decided to update the content to reflect the current version — Google Analytics 4.
Form submission is one of the main ways to collect leads on a website. The simplest way to gain more insights is to send form submission data to Google Analytics 4.
There are many ways to implement forms, which means there are also many ways to track them. I’ve already written an article on how to track user interactions with forms using Google Tag Manager. But that article didn’t cover working with the basic Form Submission trigger, which I want to walk you through now.
Here’s the algorithm: first, try the method from this article. If it doesn’t work — check out the one mentioned above. There’s also another blog post about tracking form submissions using the Element Visibility trigger.
Before we begin, let’s cover why the method below may not work. There are only two main reasons:
submit
event doesn’t occur. The Form Submission trigger relies on the submit
event in the browser. If it’s not triggered, the tracking won’t work. This often happens when custom requests like AJAX are used to submit the form.submit
event occurs, but doesn’t reach the document
level. GTM doesn’t attach event listeners to every form individually; it listens at the document
level. If something (like a jQuery handler returning false
) stops event propagation, GTM won’t detect the submission.If your form falls into one of these scenarios, you’ll either need to coordinate with your developer or use one of the alternative methods discussed in other blog articles.
Configuring a Form Submission trigger in GTM is very similar to working with the Just Links trigger. You’ll find parameters like Wait for Tags and Check Validation, which serve nearly identical functions.
In practice, unless you have specific needs (e.g. dealing with form errors), most of these parameters are not used. The main configuration is usually set under the Trigger Conditions.
It’s always puzzled me why GTM even includes a Forms category for built-in variables, as their data is nearly identical to variables in the Clicks category. But for completeness, let’s briefly go through them.
gtm.element
from the dataLayer.gtm.elementClasses
).gtm.elementId
).target
attribute (gtm.elementTarget
).href
or action
attribute (gtm.elementUrl
).textContent
or innerText
.In practice, you usually don’t need to use the Forms variables — the equivalent ones in the Clicks category will work just fine.
Now that you understand the theory, let’s move on to practical setup.
To set up the trigger, we first need to identify something unique about the form — such as its ID or a CSS selector. Open the page’s source code and find the <form>
tag.
Copy the value of the id
attribute (e.g. searchform
). Go to GTM and create a new Form Submission trigger. Under Trigger Conditions, choose the Click ID variable and paste in the ID value.
If everything is set up correctly, you’ll see the trigger fire when the form is submitted in GTM preview mode:
Then set up a tag to send the event to Google Analytics 4. Example below:
If your form doesn’t have an ID, you can use CSS selectors instead. Right-click the form element in the browser’s dev tools and select Copy > Copy selector:
To ensure you’ve copied a selector that accurately captures the form, you can use my PROANALYTICS browser extension, which highlights all matching elements on the page.
When configuring the trigger, use Click Element in the Trigger Conditions, and select Matches CSS selector as the condition. Then paste your copied selector into the input field:
The tag setup for sending data is the same as described in the previous section.
Tracking form submissions with the basic trigger is a simple yet effective method. If you’re lucky, your setup process will look like this:
Also check out these related articles on tracking user actions:
If you enjoyed this content, subscribe to my LinkedIn page.
I also run a LinkedIn newsletter with fresh analytics updates every two weeks — here’s the link to join.
Web Analyst, Marketer