# Events when form is sent

**URL:** <https://community.hubspot.com/t/events-when-form-is-sent/11410>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [September 10, 2018, 1:45pm UTC](https://community.hubspot.com/t/events-when-form-is-sent/11410 "2018-09-10T13:45:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 10, 2018, 1:45pm UTC](https://community.hubspot.com/t/events-when-form-is-sent/11410/1 "2018-09-10T13:45:37Z")

</div>

Hi,  
I was trying to change the form embedded including an event when the form is sent.  
I made this code, but I crashed the form.

I have no idea what could be happening. Is there any problem with the onForm?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [September 11, 2018, 3:19pm UTC](https://community.hubspot.com/t/events-when-form-is-sent/11410/2 "2018-09-11T15:19:59Z")

</div>

Hi @Vivian,

Are you using `onFormSubmit` per [this article](https://growth.org/discuss/adding-custom-google-analytics-code-to-forms-in-hubspot)?

This method should work. If you’re still encountering issues, please include the modified embed code below.

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 11, 2018, 3:58pm UTC](https://community.hubspot.com/t/events-when-form-is-sent/11410/3 "2018-09-11T15:58:02Z")

</div>

Hi [@Isaac\_Takushi](https://community.hubspot.com/u/Isaac_Takushi)  
I used it. I planned like this:

hbspt.forms.create({  
portalId: “-----”,  
formId: “--------------------”,  
onFormSubmit: function($form) {  
analytics.track(‘form send’, {  
category: ‘Send’,  
label: ‘send contact’  
}  
)};,  
target: ‘.formPst’,  
onFormSubmit: function() {  
window.dataLayer.push({  
event: ‘lead\_conversion’+window.location.pathname.split(///i).join(‘\_’),  
formId: ‘--------------------’  
});  
}  
});  
// ]]\>

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [September 14, 2018, 5:44pm UTC](https://community.hubspot.com/t/events-when-form-is-sent/11410/4 "2018-09-14T17:44:51Z")

</div>

Hi @Vivian,

My test form breaks as well when I place two instances of `onFormSubmit` in the embed code. If you add the second function within the first `onFormSubmit`, does it work?
