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 parameter and within I placed a Google Analytics event tracking snippet. 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”></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?