The problem
When you receive a new request, everything went well. The opposite, however, tells you nothing about the obstacles your prospects met: they did not see the form, opened it then left, or gave up at a specific field.
These 3 cases lead to 3 distinct measurements, to avoid any decision based on hunches such as shortening the form, changing the page or adding a phone number.
The 3 steps to measure
The visitor's journey on a form comes down to 3 steps.
- Form viewed. The form appears on the visitor's screen. This is not always the case when it sits at the bottom of the page.
- Form started. The visitor selects a first field.
- Form submitted. A confirmation message usually appears.
The abandonment rate between 2 steps shows where to act. Few forms viewed: the problem is the page or the placement. Many views and few starts: the form is intimidating or the message is unclear. Many starts and few submissions: a field blocks visitors.
GA4 offers the enhanced measurement "Form interactions", which produces the form_start and form_submit events. form_start fires on the first interaction with a form. These 2 events already exist, but the "viewed" step and the problem field are missing. That is the topic of this article!
Set up the tracking in Google Tag Manager
The principle applies to GA4 with Google Tag Manager.
1. The "viewed" step
In Google Tag Manager, create a trigger of type Element Visibility:
- Selection method: ID, value
contact(the ID of the example form). - Fire this trigger: Once per page.
- Minimum percent visible: 50 (default value).
Attach a GA4 event tag named form_view to it, with the form_name parameter as a fixed value (contact).
2. The "started", "submitted" and abandonment steps
This is where the trick happens. The intuitive method sends an event for every field filled in: a form with 8 fields produces up to 8 events per visit, the list of parameters grows and the report becomes unreadable. The proposed method reverses the logic. A single event is collected when the visitor leaves the page without having submitted the form. It carries 3 pieces of information:
last_field: the name of the last field selected.fields_filled: the number of fields filled in at that moment.last_field_filled: "yes" if the last field selected contained a value, "no" otherwise.
You get a report of 5 rows, one per field, which shows the problem steps.
Create a Custom HTML tag that follows the interactions of the form. Fire it on the page view (DOM Ready) of the pages that contain the form. Note that it does not collect anything itself yet: it pushes 3 events to the data layer (form_begin, form_sent and form_abandon).
<script>
(function () {
var form = document.querySelector('#contact');
if (!form || form.getAttribute('data-tracked')) { return; }
form.setAttribute('data-tracked', '1');
var last = '';
var lastEl = null;
var begun = false;
var sent = false;
var left = false;
window.dataLayer = window.dataLayer || [];
function isFilled(el) {
return (el.type === 'checkbox' || el.type === 'radio')
? el.checked : el.value !== '';
}
function filled() {
var n = 0;
for (var i = 0; i < form.elements.length; i++) {
var el = form.elements[i];
var skip = !el.name || el.type === 'hidden' || el.type === 'submit' ||
el.type === 'button' || el.type === 'password';
if (skip) { continue; }
if (isFilled(el)) { n++; }
}
return n;
}
function push(name) {
window.dataLayer.push({
event: name,
form_name: form.id,
last_field: last,
fields_filled: filled(),
last_field_filled: lastEl ? (isFilled(lastEl) ? 'yes' : 'no') : ''
});
}
form.addEventListener('focusin', function (e) {
var t = e.target;
if (!t.name || t.type === 'hidden' || t.type === 'submit') { return; }
last = t.name;
lastEl = t;
if (!begun) {
begun = true;
push('form_begin');
}
});
form.addEventListener('submit', function () {
sent = true;
push('form_sent');
});
function leave() {
if (!begun || sent || left) { return; }
left = true;
push('form_abandon');
}
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'hidden') { leave(); }
});
window.addEventListener('pagehide', leave);
})();
</script>
What the code does:
form_beginis produced on the first field selected.focusindetects each field selected and remembers the last one.submitgeneratesform_sent. This event only fires if the browser has validated the submission.leaveproducesform_abandon, once per page view, if the form was started and not submitted.visibilitychangeandpagehidecover closing the tab, navigating to another page and, on mobile, switching to another app.
3. A single GA4 tag for the 3 events
Create a new tag, this time of type GA4 Event, whose event name is the built-in variable Event (written {{Event}} in the field). Trigger: Custom Event, value ^form_(begin|sent|abandon)$, with the "Use regex matching" option ticked. Event parameters, each read by a data layer variable of the same name: form_name, last_field, fields_filled, last_field_filled.
4. Registering the parameter in GA4
A parameter only appears in reports once it is registered. In GA4, open Admin, Data display, Custom definitions, then Create custom dimension. Choose the Event scope and the parameter name last_field. Repeat for last_field_filled, as well as for form_name if you track several forms. Register the number of fields filled in as a dimension or as a custom metric. The dimension is not retroactive: events sent before it was created do not appear in it.
Overlap with enhanced measurement: form_start and form_submit from enhanced measurement coexist with form_begin and form_sent. The names differ on purpose. It is up to you to decide whether to adapt the names, keep the native events or turn them off.
Example: finding the field that causes abandonment
Here is an example for a contact form of 5 fields, in this order: name, company, email, phone, message:
| Step | Event | Total | Abandonment from the previous step |
|---|---|---|---|
| Form viewed | form_view | 1,000 | - |
| Form started | form_begin | 380 | 62% |
| Form submitted | form_sent | 190 | 50% |
Half of the visitors who started the form abandoned it. We then break this down by last field selected:
| Position | last_field | Abandonments | Share | Field empty (no) | Field filled (yes) |
|---|---|---|---|---|---|
| 1 | name | 14 | 7% | 1 | 13 |
| 2 | company | 25 | 13% | 4 | 21 |
| 3 | 22 | 12% | 3 | 19 | |
| 4 | phone | 71 | 37% | 59 | 12 |
| 5 | message | 58 | 31% | 41 | 17 |
For 37% of abandonments, the last field selected before leaving is the phone field, the 4th of 5. It was empty in 59 cases out of 71: the visitor selected it without typing anything, after the first 3 fields of the form. If it is mandatory, it would be wise to make it optional. The message field, 5th and last, was empty in 41 cases out of 58: an example request or a guided question helps get the writing started. I'll explain how to reproduce this next!
The last_field_filled parameter refines the reading. With "no", the field itself is the blocker. With "yes", the visitor filled it in then left: the blocker is more likely the next field or the submission.
The metric for the number of fields filled in completes the analysis. An abandonment on the phone field with fields_filled at 3 indicates high engagement: the visitor filled in almost everything and one of the last fields blocks them. The same abandonment with fields_filled at 0 indicates low engagement: the visitor selected the field without filling in anything.
Reading it in Google Analytics
The funnel
In Explore, create a Funnel exploration. Define 3 steps by event name: form_view, form_begin, form_sent. The exploration displays the number of users at each step and the abandonment rate between 2 steps.
The problem field
Create an exploration in the Free form format (table). Row: the custom dimension last_field. Column: the custom dimension last_field_filled. Value: Event count. Filter: event name equals form_abandon. You get the table from the example.
Precautions when sending on page close
An event sent at the moment the page closes can be interrupted by the browser. The page switching to the hidden state (visibilitychange) is the last reliable moment for tracking, including on mobile. There is no guarantee that everything gets tracked: the abandonment figure is therefore a minimum. Check in GTM preview mode that the tag fires, then in the browser's network tab that the request is sent. Finally, compare form_begin minus form_sent with form_abandon. A small difference is normal, a large difference may point to a script that is not compatible with your site.
Pitfalls
- Fields prefilled by the browser. Autofill completes several fields at once. They count in
fields_filled: read this number with that caveat! - Multi-step form. If the steps are screens within a single HTML form, the script works and
last_fieldshows the step reached, provided the fields have distinct names. If each step is a separate form, add a Custom HTML tag per form with its ID. If the form loads after the page (modal window, lazy loading), fire the tag when the form appears. - Mobile and tab switching. A visitor who switches to another app (or to another tab on a computer) hides the page. The
form_abandonevent fires, even if the visitor comes back and submits afterwards. To isolate these cases, use a segment to exclude the sessions that contain bothform_abandonandform_sent. - Submission without page reload. For a form submitted via AJAX, the browser's
submitcomes before the server's response. If the server rejects the request,form_senthas already fired. For an exact figure, fireform_senton the confirmation page or on the success message.
Tools
- Google Tag Manager: visibility trigger, Custom HTML tag, GA4 event tag, preview mode.
- Google Analytics 4: event-scoped custom dimension, funnel exploration, free form exploration.
- Browser console: reading the data layer and the requests sent when the page closes.
Setting up this form tracking is part of the tracking expertise.