How to accurately track Form Submissions


Tracking form submissions is essential for understanding user interactions, conversion rates, and optimizing website performance. However, many digital marketers and developers struggle with unreliable tracking methods. Most tag management tools like Google Tag Manager (GTM), Tealium iQ, and Adobe Launch offer event-based tracking triggers, but they often fail due to modern form submission techniques.

Why Traditional Form Tracking Fails

Tag management triggers typically listen for the submit event in HTML forms. However, many forms do not rely on this event to send data. Instead, they use:

Additionally, some tracking methods rely on submit or click events, which can also track failed form submissions, leading to misleading data.

Identifying Your Form Submission Method

To determine how a form sends data, follow these steps:

Implementing Proper Form Tracking

1. Tracking Fetch API Requests

If your form uses the Fetch API, override the fetch method to insert tracking logic:


old_fetch = window.fetch;

window.fetch = function () {

    /* Uncomment the below lines for debugging */

    // console.log(this);

    // console.log(arguments);

 

    const fetch = old_fetch.apply(this, arguments);

    fetch.then((response) => {

        try {

            /* Insert your tracking logic here */

        } catch (e) {}

    });

    return fetch;

};

2. Tracking AJAX (XHR) Requests with jQuery

If your website uses jQuery, track AJAX requests using an event listener:


$(document).ajaxSuccess(function (event, xhr, options) {

    try {

        /* Insert your tracking logic here */

    } catch (e) {}

});

3. Tracking XHR Requests Without jQuery

If your site doesn’t use jQuery, modify the XMLHttpRequest.prototype.send method:


old_send = XMLHttpRequest.prototype.send;

XMLHttpRequest.prototype.send = function () {

    try {

        /* Insert your tracking logic here */

    } catch (e) {}

    old_send.apply(this, arguments);

};

Best Practices for Form Tracking

By implementing these tracking methods, you can achieve accurate form submission tracking and improve your website’s analytics reliability.