HubSpot onFormSubmit and Other JavaScript Events


When embedding a HubSpot form using the JavaScript script tag it is common to want to apply some of your own functions after the form has submitted. This can be used for adding conversion pixels for Google Ads and Facebook after the form is submitted. Another use case is modifying the form markup after the form has loaded.

Source

onFormSubmit

Called when the form starts to submit but has not completed

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
       console.log("Form Submit started");
   }
});

onFormSubmitted

Called after the form is submitted

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
       console.log("Form Submitted!");
   }
});

onBeforeFormInit

Called before form is inserted on the page

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onBeforeFormInit') {
       console.log("HubSpot Form starting to load");
   }
});

onFormReady

Called after the form is loaded on the page

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
       console.log("HubSpot form added to page");
   }
});

 

About the Author

Jake Lett is a results-driven Detroit based B2B marketing consultant with 15+ years of hands-on experience managing SEO and PPC campaigns across manufacturing, SaaS, and professional services industries. He’s a Certified Google Ads Specialist and HubSpot CMS Developer who has personally managed budgets ranging from $500 to over $10,000/month.

Jake specializes in helping small businesses and solo marketers get more from lean ad budgets—using practical strategies that drive qualified leads, not just traffic. He shares real-world lessons on his blog, YouTube channel, and in his published books on digital marketing.



Related posts

Tags: , ,

Want to Get Email Updates of New Articles?

Join My Email Newsletter