
Forminator GTM Event Listener
Free Forminator tracking code for GTM. Fires forminator_form_submit once per saved entry, for AJAX and Page Reload forms, popups and redirects. GA4 ready.
forminator_form_submit Get the code
Free Gravity Forms tracking code for GTM. Fires gravity_form_submit only after the entry is accepted, for AJAX, reload and redirect forms. GA4 and Ads ready.

Copy this into a Custom HTML tag in Google Tag Manager. It pushes gravity_form_submit to the dataLayer when the Gravity Forms form is sent.
<script>
/* Gravity Forms listener by MD Niamul - mdniamul.com
Fires gravity_form_submit once per real Gravity Forms submission:
- AJAX forms with a message confirmation (gform_confirmation_loaded)
- AJAX forms that redirect to another page or URL
- non-AJAX forms that reload the page with the confirmation message
Validation errors, spam (honeypot) and failed submits send nothing. */
(function () {
if (window.__mdnGravityBasic) return; // tag fired twice: keep one copy
window.__mdnGravityBasic = true;
window.dataLayer = window.dataLayer || [];
var KEY = 'mdn_gf_pending';
var sent = {};
function store(obj) { try { if (obj) sessionStorage.setItem(KEY, JSON.stringify(obj)); else sessionStorage.removeItem(KEY); } catch (e) {} }
function load() { try { return JSON.parse(sessionStorage.getItem(KEY) || 'null'); } catch (e) { return null; } }
function formName(id) {
var t = document.querySelector('#gform_wrapper_' + id + ' .gform_title');
return t ? t.textContent.replace(/s+/g, ' ').trim() : '';
}
function push(id, name, type) {
id = String(id || '');
if (!id || sent[id]) return;
sent[id] = true;
store(null);
window.dataLayer.push({
event: 'gravity_form_submit',
form_id: id,
form_name: name || '',
confirmation_type: type,
page_path: window.location.pathname
});
}
// 1) Remember which form was sent (button click, Enter key, submit)
function remember(form) {
if (!form || !/^gform_d+$/.test(form.id || '')) return;
var id = form.id.replace('gform_', '');
sent[id] = false;
store({ id: id, name: formName(id), path: window.location.pathname, at: new Date().getTime(), status: 'sent' });
}
document.addEventListener('click', function (e) {
var b = e.target && e.target.closest ? e.target.closest('[id^="gform_submit_button_"], .gform_button') : null;
if (b && b.form) remember(b.form);
}, true);
document.addEventListener('submit', function (e) { remember(e.target); }, true);
document.addEventListener('keydown', function (e) {
if (e.key === 'Enter' && e.target && e.target.form && e.target.tagName !== 'TEXTAREA') remember(e.target.form);
}, true);
// 2) AJAX: validation error (form comes back) or redirect (watch the AJAX frame)
function watchFrames() {
var frames = document.querySelectorAll('iframe[id^="gform_ajax_frame_"]');
for (var i = 0; i < frames.length; i++) {
if (frames[i].__mdn) continue;
frames[i].__mdn = true;
frames[i].addEventListener('load', function () {
var p = load();
if (!p) return;
try {
var html = this.contentDocument && this.contentDocument.documentElement ? this.contentDocument.documentElement.innerHTML : '';
if (html.indexOf('GF_AJAX_POSTBACK') === -1) return;
if (html.indexOf('gformRedirect(){') !== -1) { p.status = 'redirecting'; store(p); }
else if (html.indexOf('gform_confirmation_wrapper') === -1) store(null); // form back = errors
} catch (e) {}
});
}
}
// 3) AJAX message confirmation
function hookjQuery() {
var $ = window.jQuery;
if (!$ || hookjQuery.done) return !!hookjQuery.done;
hookjQuery.done = true;
$(document).on('gform_confirmation_loaded', function (e, id) {
var p = load();
push(id, p && String(p.id) === String(id) ? p.name : formName(id), 'message');
});
return true;
}
// 4) After a page load: non-AJAX confirmation, or the redirect target page
function onLoad() {
var p = load();
if (!p) return;
var age = new Date().getTime() - (p.at || 0);
if (age > 10 * 60 * 1000) { store(null); return; }
var msg = document.getElementById('gform_confirmation_message_' + p.id);
if (msg) { push(p.id, p.name, 'page_reload'); return; }
if (document.querySelector('#gform_wrapper_' + p.id + '.gform_validation_error')) { store(null); return; }
if (p.status === 'redirecting' || (p.path !== window.location.pathname && age < 2 * 60 * 1000)) {
push(p.id, p.name, 'redirect');
}
}
var tries = 0;
(function wait() {
watchFrames();
var ok = hookjQuery();
if (tries === 0) {
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', onLoad); else onLoad();
}
if (++tries < 40 && (!ok || !document.querySelector('iframe[id^="gform_ajax_frame_"]'))) setTimeout(wait, 250);
})();
})();
</script>
This code is also on GitHub with a README and version history: github.com/mdniamul0/gravity-forms-gtm-listener
gravity_form_submitgravity_form_submit, use it on your GA4, Google Ads or Meta tag, then Preview and Publish.After you install the code and send a test entry, this is the data that shows up in GTM. You don’t need to paste it anywhere. Use it to check the listener works and to create Data Layer Variables such as form_id.
{
event: 'gravity_form_submit',
form_id: '3',
form_name: '',
confirmation_type: 'message',
page_path: '/contact/'
}gravity_form_submit. To track one form only, add the condition form_id equals your form’s ID (the number in the shortcode, for example 3).form_id, form_name and confirmation_type.generate_lead), Google Ads conversion or Meta Pixel Lead event on the gravity_form_submit trigger.gravity_form_submit shows up once. Then publish your container.Good to know: the event fires only after Gravity Forms accepts the entry. A form that comes back with errors sends nothing, and the free code never sends what people typed. It skips the hidden honeypot (anti-spam) field, so a spam trap labelled “Name” can never be read as a real name.
Want the full GA4 setup? Read my guide on WordPress form tracking in GA4 with GTM. If you’d rather have it done for you, see my Google Ads tracking specialist page and my server-side tracking service.
The free code tells GTM that a lead happened. The advanced code tells your ad platforms who the lead is and where they came from.
| What you get | Basic Free | Advanced Paid |
|---|---|---|
| Fires only on a successful submit or booking | Yes | Yes |
| Form or platform ID in the dataLayer | Yes | Yes |
| UTM source, medium, campaign, term and content | No | Yes |
| Ad click IDs (gclid, wbraid, gbraid, fbclid, ttclid, msclkid) | No | Yes |
| SHA-256 hashed email, phone and name | No | Yes |
| First-party cookies (_fbp, _fbc, _ga, _gcl_aw) | No | Yes |
| Device, browser and visitor location | No | Yes |
| event_id for Pixel and CAPI deduplication | No | Yes |
| Ready for Google Ads Enhanced Conversions and Meta CAPI | No | Yes |
| Install help from MD Niamul | No | Yes |
Built for agencies and brands that run paid ads. Every lead carries the data that Meta, Google Ads, TikTok and GA4 need to match the person and credit the right campaign.
One-time price. Start with the code, or let me set everything up for you.
You install it yourself
We set it up together
I install and test it
Browser + server tracking
Stape.io plan paid separately
Server-side: Server-side tracking runs on Stape.io. The Stape plan is not included: you pay Stape directly (they have a free plan for small sites). I set it up on your account. Get Stape (global) · Stape EU server
One-time prices in USD. You pay me directly and get an invoice in your client portal.
Not sure which one fits? Message me and I will tell you what you need.
Already bought the advanced code? Get it in your client portal.
Yes. With AJAX it listens to Gravity Forms' own gform_confirmation_loaded event and the AJAX redirect. Without AJAX it checks the page after the reload for the confirmation message, or the redirect page.
It fires on the click, also when a required field is empty or the CAPTCHA fails. This code waits until Gravity Forms has accepted the entry, so failed submits never count.
That works too. The listener remembers the sent form for a short time and fires on the thank-you page, as long as GTM loads there. Visitors who block storage in their browser can't be counted this way.
Message me on WhatsApp. After payment I add it to your client portal with the code, a setup video, a PDF guide and a GTM import file.
Yes. The basic code on this page is free to copy and use on your own or your clients’ sites. It fires the gravity_form_submit event when the Gravity Forms form is sent.
The basic version only tells GTM that a lead happened. The advanced version also sends UTM values, ad click IDs, hashed email and phone, first-party cookies, device and location data and an event_id, so Meta CAPI, Google Ads Enhanced Conversions and GA4 get much better data.
Message me on WhatsApp, book a call or use the contact form. It is a paid, one-time purchase, and I can install it for you if you like.
No. The listener runs inside Google Tag Manager and listens for the form’s own success signal. You don’t need to edit the form or your theme.
💬 Want this implemented without mistakes?
I’ve completed 850+ projects for 600+ businesses and 15+ agencies, helping clients generate $11M+ in revenue with accurate client-side & server-side tracking and business automation.
⮏ My core services include:
⨭ GoHighLevel Automation — build CRM pipelines, WhatsApp automation, AI voice workflows & automated follow-ups end-to-end.
⨭ AI Agent Automation — deploy AI chatbots & agents for 24/7 lead qualification and support.
⨭ Paid Ads Management — Google Ads, Meta Ads.
⨭ Full Stack SEO/GEO/AEO Manager.
⨭ CRO-Focused Web Development — Landing Pages on WordPress, Shopify, Wix, Squarespace.
⨭ Google Tag Manager (GTM) — manage data layers & (Marketing platform Tag, Trigger & Variables).
⨭ Custom Code by GTM — HTML, CSS & JavaScript for advanced marketing platform tracking.
⨭ Server-Side Tracking — recover data lost to ITP & ad blockers (Official Stape Partner).
⨭ Google Analytics 4 (GA4) — visualize customer journeys.
⨭ Multi-Channel CAPI — Facebook, TikTok, Pinterest & Snapchat Conversion API & Klaviyo email marketing tools.
⨭ Third Party Checkout Conversion Tracking — Shopify, Stripe, GoKwik, Shiprocket, PayPal or more.
⨭ Google Consent Mode (GCM) — maintain GDPR compliance.
⨭ Marketing Automation — streamline workflows (Zapier/n8n/Make).
⨭ CRM Conversion Tracking — link offline sales to ads.
⨭ Tag Management — GTM & Third-Party Checkout Tracking.
⨭ Offline & CRM Tracking — HubSpot, Salesforce, Zoho, Pipedrive, Odoo, Webhook & Sheet.
⨭ Advanced Analytics — GA4, Google Looker Studio & BigQuery (SQL) for deep data visualization.
If you want your Gravity Forms Tracking done right the first time, message me.