Home › How-tos › The Secret Setups › HubSpot
How to track HubSpot form submissions in the dataLayer
Live guide · Checked 28 October 2026 · Updated 28 October 2026 · Checked every week against HubSpot's own help pages
Catch HubSpot's form submitted event, for both the new and the older embed, and push it into the dataLayer as a lead.
- Time
- 15 minutes
- You will need
- A HubSpot form embedded on your site
- Google Tag Manager with the generate_lead trigger
- Stuck?
- Troubleshooting or ask us a question
Step by step
Know which embed you have
HubSpot has two embeds. The newer one uses
hs-form-frame, the older onehbspt.forms.create. Look at your page's embed code: the listener below handles both.Add the listener
In Tag Manager, a Custom HTML tag on All Pages:
<script> (function () { var done = {}; function lead(formId) { if (done[formId]) return; done[formId] = true; window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'generate_lead', form_id: 'hubspot-' + formId, lead_type: 'enquiry', value: 50, currency: 'GBP', lead_id: 'L-' + Date.now() }); } // Older embed (hbspt.forms.create): HubSpot posts a message to the page window.addEventListener('message', function (e) { if (e.data && e.data.type === 'hsFormCallback' && e.data.eventName === 'onFormSubmitted') lead(e.data.id || 'form'); }); // Newer embed (hs-form-frame): HubSpot fires a page event window.addEventListener('hs-form-event:on-submission:success', function (e) { lead((e.detail && e.detail.formId) || 'form'); }); })(); </script>Don't use the click trigger
HubSpot forms often live in an iframe and validate after the click, so Tag Manager's own Form Submission trigger misses or over-counts them. The events above only fire after HubSpot accepts the form.
Test it
In Preview, send a test form. Tag Assistant should show
generate_leadwithform_idstartinghubspot-. Delete the test contact in HubSpot after.Publish
Publish. Every lead tag on
CE - generate_leadnow counts HubSpot leads.
Tips from people who set these up every week
- HubSpot can also send leads to Google Ads and Meta itself (Marketing > Ads). If you turn that on, don't also send the same conversion from Tag Manager.
- The hidden fields Secret Setup works with HubSpot: add hidden gclid and utm_ properties to the form.
Troubleshooting: questions and answers
Neither event fires.
Your form may be a HubSpot landing page, not an embed on your site. Track those pages with the HubSpot tracking code and GA4 instead.
Official help pages
Let Claude fix the rest of your funnel
Lead Focus is 12 Claude Skills that find the stage of your funnel that's costing you leads, then fix it: ads, landing pages, follow-ups and tracking. One payment, 12 months of updates, and a 14-day refund.
Get Lead Focus · $29.99Still stuck, or have a question?
Tell us where you got to and what you see. We read every message and reply by email, usually the same working day.