Hi, our website is hosted on Webflow and we have hubspot forms embedded on CMS pages. Is there a way we can track these hubspot form submissions on Google tag manager?
Here is the code I pasted below the form embed code <script> window.addEventListener('message', event => { if (event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'form_submission', 'formId': 'data-form-Id', // I replace with form ID 'formName': 'form name' // I replace with form name }); } }); </script>
Another thing to try - instead of pasting the code on your page, create a Tag (Custom HTML) in GTM and drop your <script> in there.
To double check whether it is working, you can also set up a Trigger as a Custom Event and add the event name there. In my case I have it named "hubspot-form-success", you would put yours, i.e. "form_submission".
Then you would see it show up in the Preview upon form submission:
✔️ Did this post help answer your query? Help the community by marking it as a solution.
You can track HubSpot form submissions embedded on Webflow CMS pages using Google Tag Manager (GTM). You'll need to set up a trigger in GTM that listens for the form submission event to do this. Since HubSpot forms may not trigger a standard form submission event, you can leverage the HubSpot form API, which provides a onFormSubmit callback. Add custom JavaScript to the embed code of your HubSpot form that pushes a custom event to the GTM data layer when a form is successfully submitted. Then, in GTM, create a trigger to listen for this custom event and configure a tag (e.g., Google Analytics event or conversion tracking) to fire when the trigger is activated. Please make sure that your GTM container is published, and thoroughly test the setup to confirm accurate tracking.