Lesson 3 of 4
HubSpot Forms
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
HubSpot forms are a classic gotcha: they don't trip GTM's built-in Form Submission trigger, because the form lives in an iframe and HubSpot reports the result through a window message instead.
You'll listen for HubSpot's hsFormCallback message and push a clean hubspot_form_submit event when onFormSubmitted fires, then tag it like any other lead. HubSpot stamps every callback with the form's id, so one listener covers every HubSpot form on the page and you can tell them apart downstream.
Goal
Catch HubSpot's onFormSubmitted callback and fire a tag on hubspot_form_submit.
Build it in GTM
Add the listener as a Custom HTML tag
Paste this into a Custom HTML tag firing on All Pages (or Initialization). It turns HubSpot form's signals into dataLayer events:
<script> window.addEventListener('message', function (e) { if (e.data && e.data.type === 'hsFormCallback' && e.data.eventName === 'onFormSubmitted') { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'hubspot_form_submit', hs_form_id: e.data.id }); } }); </script>Create a Custom Event trigger on
hubspot_form_submitGo to Triggers → New → Custom Event, set the event name tohubspot_form_submit, name it for the widget and Save.Fire a tag on it
Add a GA4 Event tag (or theCustom HTML - Teststand-in) firing on that trigger, so the captured event reaches your analytics.Go deeper
Want the full production script, a walkthrough video and a downloadable GTM recipe? DumbData: HubSpot form listener script, video + GTM recipe.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
hubspot_form_submit, and your tag fires on it in Tag Assistant.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded