Using AnalyticsJS Identify on embedded Hubspot forms
This article assumes you have already installed AnalyticsJS on your website. If you've not yet installed AnalyticsJS, read our knowledgebase article on the topic.
To identify
prospects using AnalyticsJS when they submit an embedded HubSpot form, you need to trigger identify
call through the onFormSubmit
method.
The javascript for a basic HubSpot form on your site probably looks something like this:
hbspt.forms.create({
portalId: '1234',
formId: '5678'
});
To trigger an identify
call, you'll need to add the onFormSubmit
method. If the type of input in the HTML form is email
, then the following code should automatically trigger the identify
call when the form is submitted:
hbspt.forms.create({
portalId: '1234',
formId: '5678',
onFormSubmit: function(form) {
var email = form.find('input[type="email"]').val();
if (!email) {
if (console && console.log) {
console.log("CaliberMind: no email found in form.")
}
} else if (!analytics) {
if (console && console.log) {
console.log("CaliberMind: no analytics found on page.")
}
} else {
analytics.identify(email, { email: email });
}
}
});
For more information on how to customize your embedded HubSpot forms, see HubSpot's extensive documentation on the topic.