Mastering HubSpot form tracking in GA4 ensures you never miss a lead conversion due to iFrame or JavaScript limitations.
HubSpot forms often load via iFrames or dynamic JavaScript. Standard GTM "Form Submission" triggers can't see these events because they don't bubble up to the main window. To fix this, we need a custom listener that communicates between the HubSpot form and your Data Layer.
This method captures the onFormSubmitted event directly from HubSpot's postMessage API. It is the most reliable way to track conversions without relying on thank-you page redirects.
In GTM, create a Custom HTML Tag triggered on All Pages:
hubspot_form_success.generate_lead and fire it using the trigger above.If you have direct access to the website code and don't want to use GTM for the listener, you can add the tracking event directly into the HubSpot embed script:
Tracking when users fail to submit a form is crucial for CRO. Add this snippet to your GTM listener to capture validation errors:
Using a GTM listener is the cleanest way to track HubSpot forms in GA4. It prevents duplicate data, works with iFrames, and provides granular insights into user behavior. Always test your setup using the GTM Preview mode and GA4 DebugView before going live.