# OnFormSubmit breaks form

**URL:** <https://community.hubspot.com/t/onformsubmit-breaks-form/26124>\
**Category:** Reporting & Analytics\
**Tags:** forms\
**Created:** [September 29, 2020, 4:48pm UTC](https://community.hubspot.com/t/onformsubmit-breaks-form/26124 "2020-09-29T16:48:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mattg1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mattg1/32/59606_2.png) [@Mattg1](https://community.hubspot.com/u/Mattg1)\
**Post date:** [September 29, 2020, 4:48pm UTC](https://community.hubspot.com/t/onformsubmit-breaks-form/26124/1 "2020-09-29T16:48:24Z")

</div>

I am trying to track form submissions using Google Analytics Events. So I am in the process of switching the form implementation from selected within modules to embedded scripts. To do this I am adding the [onFormSubmit](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options) parameter and within I placed a Google Analytics [event tracking snippet](https://developers.google.com/analytics/devguides/collection/analyticsjs/events? __hstc=20629287.27bf6ebcb31dcc5e7eb2b077c6923b1f.1594301809145.1601390183624.1601392168145.98&__ hssc=20629287.5.1601392168145&__hsfp=1874026354). I’ve linked articles to the documentation on each.

Here’s what my code looks like:

\<script charset=“utf-8” type=“text/javascript” src=“[//js.hsforms.net/forms/v2.js](https://js.hsforms.net/forms/v2.js)”\>\</script\>  
\<script\>  
hbspt.forms.create({  
portalId: “XXXXX”,  
formId: “XXXXXXXXXXXXXXXXXXX”,  
onFormSubmit: function($form) {  
ga(‘send’, ‘event’, ‘Form’, ‘submit’, ‘BlogSubscribe’);

}  
});  
\</script\>

But this code above does not output a form on my page.

If I comment out the onFormSubmit section, (just these 3 lines below) the form ends up working:

// onFormSubmit: function($form) {  
// ga(‘send’, ‘event’, ‘Form’, ‘submit’, ‘BlogSubscribe’);  
// }

What is wrong with the original code with the onFormSubmit parameter?

---

<div class="post-metadata">

**Author:** ![mike-ward](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mike-ward/32/26595_2.png) [@mike-ward](https://community.hubspot.com/u/mike-ward)\
**Post date:** [October 6, 2020, 4:53pm UTC](https://community.hubspot.com/t/onformsubmit-breaks-form/26124/2 "2020-10-06T16:53:32Z")

</div>

Hi @Mattg1 ,

Doesn’t _look_ to be anything wrong with it to me. Are there any console errors when the page loads (you probably already know this, but right-click =\> inspect to load the dev tools in Chrome)?

Is JQuery being loaded on the page, and using its default $ namespace? Otherwise that $form reference won’t work and could be the problem.

If you can share a test page that would be helpful to help debug a bit further (if you can!)

Cheers,

Mike

---  
_Did I answer your question? If your question is answered, please mark it as a solution. If you need more help, hit that big orange ‘Reply’ button!_
