This is a list of options that you can use if you just need to tweak a default hubspot form. If you need complete control over the styles and actions of your form, you will still want to use the Forms API.
I applied this to one of my embedded HubSpot forms, but it doesn’t seem to be tracking the event in Google Analytics. I am not using Google Tag Manager.
Here is the code I used:
hbspt.forms.create({
css: ‘’,
portalId: ‘XXXXXXX’,
formId: ‘XXXXXXX-XXX-XXX-XXXXXXX’,
onFormSubmit: function($form) {
“_gaq.push([’_trackEvent’, ‘Contact’, ‘contact_us_form’, ‘Main_Contact_Us’, false]);”
},
submitButtonClass: ‘btn btn-primary btn-hubspot’,
locale: ‘en’,
translations: {
en: {phoneInvalidLengthOrFormat: ‘Please enter a valid phone number.’}
}
});
I realize that this is very similar to the question posed in this forum, but I followed these instructions and am still running into issues.
Where you paste that code?
“Here is the code I used:
hbspt.forms.create({
css: ‘’,
portalId: ‘XXXXXXX’,
formId: ‘XXXXXXX-XXX-XXX-XXXXXXX’,
onFormSubmit: function($form) {
”_gaq.push([’_trackEvent’, ‘Contact’, ‘contact_us_form’, ‘Main_Contact_Us’, false]);"
},
submitButtonClass: ‘btn btn-primary btn-hubspot’,
locale: ‘en’,
translations: {
en: {phoneInvalidLengthOrFormat: ‘Please enter a valid phone number.’}
}
});"
I have an hubspot form and i want to do that on click button, but i don’t know where is the place to paste this code p.e. “ga(‘send’, ‘event’, ‘Videos’, ‘play’, ‘Fall Campaign’);”
Hi Derek, I’m trying to replicate this in my form with no sucess… could you please add the onFormSubmit function to the below code? everytime I add it the form doesnt display… thanks a lot!
You’ll want to put that inside the onFormSubmit callback, where the _gaq.push call is now. You’ll probably also want to check out the ga.js to analytics.js migration docs, if you haven’t already:
There isn’t currently a way to access the onFormSubmit callback globally or via the UI, so you’d need to either replace it with an embedded form or use a workaround like detecting the hsvalidatedsubmit event (see below).
dadams:
Hi @Arlo_Gilbert The hsvalidatedsubmit event is triggered after the data in a HubSpot form passes validation. You can detect when that event is triggered, but anything you do after detecting the event would not block the submission from proceeding. The onFormSubmit function gets executed as part of the submission itself, so anything you include in that function will be executed before the form proceeds with the submission.
Hi, I’m trying to trigger GA events from an embedded hubspot form as well, but it’s not working after following the instructions. Here is my form code - what have I done incorrectly?
Hi all - battling with this same issue. I really think that the better route to follow is to first implement Google Tag Manager and then republish you GA script but through GTM.. “Google Tag Manager is a tag management system that allows you to create and monitor tags on a user interface, without writing new code each time you want to construct a tag. You simply embed the Google Tag Manager code into each page of your website. This eliminates the manual process of creating tags, making your marketing process more efficient and precise.”
Once done - you will be in a much better position to track conversions in Hubspot. With GTM installed here is how you can track HS forms in GTM and GA:
I have followed this GTM instrucion as followed but the tag is not firing. In the trigger, I used the option to record every embedded form completion. So I used the “hbspt-form” option in the trigger which is found from the page where the form is embedded.
I have a similar problem since we should embed a Google Analytics event tracking code in HubSpot form. Conversion is when a customer clicks a send button of the contact form. My question is that where is the right place for GA Event tracking code? And is this type of code the best option in this case:
ga(‘send’, ‘event’, [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
I tried the above code and replaced Category, Action and Label fields by our campaign names from Google Analytics.
Here’s the code of the HubSpot form:
<!--[if lte IE 8]>
<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/v2-legacy.js”></script>
<![endif]-->
<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/v2.js”></script>
<script>
hbspt.forms.create({
region: “na1”,
portalId: “4128102”,
formId: “3a46f667-8e71-464a-8b45-d0956e30b917”
});
</script>