How Do You Get Form Tracking Code?
You do not need to write a form listener from scratch. Here is where to get tested code for almost any form platform, and how to wire it into GTM.

Short answer: you almost never need to write it yourself. Someone has already written and tested a listener for your form platform, and you can copy it.
This post shows you where to get that code, how to install it in Google Tag Manager, and how to turn the event it produces into conversions in GA4, Google Ads and Meta.
What is form tracking?
Form tracking means knowing when someone successfully submitted a form on your site, and being able to act on it. Fire a conversion, build an audience, add the person to a report.
It sounds trivial. It is not, because of one thing: most modern forms never load a new page.
Why it is harder than it looks
Old forms posted to a server and loaded a thank you page. You tracked a page view on that URL and you were done.
Modern forms submit over AJAX. The page never changes. The form is swapped for a success message, the URL stays the same, and every page based tracking method sees nothing at all.
Worse, a lot of form tools render the form inside an iframe on a different domain. Your JavaScript cannot see inside it, so even listening for a click on the submit button does not work.
What an event listener actually does
An event listener is a small piece of JavaScript that waits for the form tool to announce that something happened, then pushes a message into the GTM data layer.
Every serious form platform announces its own events. They just do it in their own way:
A DOM event. Contact Form 7 fires wpcf7mailsent on the document.
A jQuery event. Gravity Forms, Ninja Forms and Elementor all use this.
A postMessage. HubSpot, Typeform, Tally and Calendly send a message from the iframe to the parent page.
The listener’s job is to catch that announcement and translate it into something GTM understands. That is all it does.
Where to get the code
The best public library of these listeners is DumbData. They maintain tested listeners for around 90 tools, including almost every form platform you are likely to use.
Use theirs rather than writing your own. Not because writing one is hard, but because theirs have been used on thousands of sites and already handle the awkward cases you will not think of until they break.
The process is:
Open the DumbData listeners page.
Find your form platform in the list.
Copy the code exactly as it is.
Paste it into a Custom HTML tag in GTM.
That is genuinely it. The rest of this post is what to do with the event once it exists.
How to install the listener in GTM
In Google Tag Manager, create a new tag and choose Custom HTML.
Paste the listener code, including the script tags.
Set the trigger. All Pages works, and if the form only exists on a few pages, limit it to those.
Tick Support document.write only if the listener needs it. Almost none do.
Save, then Preview.
One detail that catches people: several listeners use jQuery. On WordPress that is usually already loaded. On a custom build it might not be. If the listener starts with jQuery and nothing happens, that is the first thing to check.
How to create the Custom Event trigger
The listener pushes an event with a name. You need a trigger that listens for that exact name.
In GTM, create a new trigger and choose Custom Event.
Type the event name exactly as it appears in the listener code. It is case sensitive.
Leave it on All Custom Events unless you want to filter by form ID.
Save.
If you want to track one specific form rather than all of them, add a condition on the form ID variable you are about to create.
How to create Data Layer Variables
Most listeners push more than just the event name. They also push a form ID, sometimes the submitted values, sometimes a step reference.
To use any of that in a tag, you need a Data Layer Variable:
In GTM, create a new variable and choose Data Layer Variable.
Set the name to exactly the key in the data layer push, for example formID or hs-form-guid.
Leave version 2 selected.
Save with a clear name like DLV Form ID.
Now you can send the form ID to GA4 as an event parameter, or use it to decide which conversion to fire.
How to send the event to GA4
Create a GA4 Event tag.
Set the event name to something clean and consistent, such as generate_lead.
Add event parameters: form_id from your Data Layer Variable, and form_name if you have it.
Set the trigger to your Custom Event trigger.
Save.
Use one event name across every form and separate them with parameters. One generate_lead event with a form_id parameter is far more useful than six differently named events.
How to send conversions to Google Ads
In Google Ads, create a conversion action with source Website, and note the conversion ID and label.
In GTM, create a Google Ads Conversion Tracking tag with those values.
Set the trigger to your Custom Event trigger.
Add a conversion value if you have one worth sending.
Turn on Enhanced Conversions and supply the hashed email if the form collects one.
If the real outcome happens later, in a CRM, this form submission is the start of the story rather than the end of it. That is a separate job: tracking qualified leads, not form fills.
How to use the event with Meta and other platforms
The same Custom Event trigger fires any tag you like. That is the point of routing everything through the data layer.
Meta. A Meta Pixel tag with the Lead standard event.
Mixpanel, Piwik PRO, Amplitude. Their GTM templates all accept a custom event trigger.
LinkedIn, Microsoft, TikTok. Same pattern with their own conversion tags.
You write the listener once and every platform reads from it. Adding a new platform later is one tag, not another listener.
How to test it
Open GTM Preview and load the page with the form.
Submit the form for real. Do not simulate it.
Check the event appears in the left hand event stream with the exact name you expect.
Click the event and open the Data Layer tab to confirm the form ID and any other values are there.
Check your tags fired, and only once.
Check GA4 realtime and, the next day, Google Ads.
Submit at least twice. A listener that fires once and then stops is a real failure mode and you will only see it on the second attempt.
Common issues
Nothing fires at all. Usually jQuery is missing, or the listener loaded after the form did. Move the trigger earlier.
It fires twice. The listener is installed in two places, often once in GTM and once hardcoded in the theme.
It fires on failed submissions. You are listening for a click or a submit rather than a success. Check which event the listener actually uses.
The form ID is undefined. The Data Layer Variable name does not match the key in the push. They are case sensitive.
It works in preview and not live. The container was not published, or a consent setting is blocking the tag.
Privacy considerations
Some listeners can capture the values people typed into the form. That is genuinely useful and it is also the part to be careful with.
Three rules that keep you out of trouble:
Never send names, emails, phone numbers or free text into GA4. It is against Google’s terms and it is the most common way sites end up with personal data where it should not be.
If you send customer data to an ad platform for matching, hash it first and only send what that platform expects.
Gate the tags behind marketing consent in your consent tool, not behind a hand rolled check: Google Consent Mode v2 in GTM
Capturing which form was submitted is low risk. Capturing what was typed into it is a decision to make deliberately.
Final thoughts
Form tracking has a reputation for being fiddly, and most of that reputation comes from people writing their own listeners badly.
Take the tested code, install it once, trigger everything from the data layer event, and it stops being a recurring problem.
Platform specific guides, each using the DumbData listener for that tool:
Need this built properly?
Form tracking is simple once the events are real events. I set up and repair tracking for ecommerce stores and lead generation businesses, so the numbers in your ad accounts match the money in your bank account.
Have a look at what I do, or book a call and we can go through your setup together.



















