APIs & Integrations

gviner
Member

Javascript event tracking in hubspot forms

Hi there

I am in the habit of using the onFormSubmit attribute with hubspot forms to allow Google Tag Manager to send an event to Google Analytics as follows.

hbspt.forms.create({
portalId: ‘xxx’,
formId: ‘yyy’,
onFormSubmit: function(){
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
‘event’: ‘formSubmissionSuccess’,
‘formName’: ‘Squeeze’
});
}
});

This works usually but sometimes it appears that it does not. When i compare form submissons in Hubspot with the events being picked up in Google Analytics for our company account there are discrepancies. Of the past 40 successful form submissions, 5 of them were not picked up by GA. There’s no filtering going on in GA to exclude some submissions so as far as i can tell, the only explanation is that sometimes the code in the onFormSubmit() is not firing. Likewise, there are no javascript errors appearing in the console that might be blocking this.

Has anyone else any experience with this or any suggestions about next steps? Any reason why it should not fire sometimes? I should say that whenever i test this myself it works just fine

Thanks
Garry

0 Upvotes
4 Replies 4
derekcavaliero
Top Contributor | Diamond Partner
Top Contributor | Diamond Partner

Javascript event tracking in hubspot forms

@gviner you might also want to investigate if those 5 submissions might have come from users who had adblockers or tracking blockers enabled. This is becoming more prevalent especially on iOS Safari opening up content blocker technology.

Derek Cavaliero
Director of Engineering

WebMechanix
www.webmechanix.com
0 Upvotes
gviner
Member

Javascript event tracking in hubspot forms

You might be right about this.The next time it happens we will ask directly if they have one of these extensions. Thanks for the idea

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Javascript event tracking in hubspot forms

Garry,

I would take a read through this post.

Your issue might be relevant to this. We are working on this now.

0 Upvotes
gviner
Member

Javascript event tracking in hubspot forms

Hi there. Thanks for commenting and sorry for the delayed response from me. The form is definitely connected. And in that post the poster says that the form submission does not make its way into the HubSpot contacts database. That is not the case here. Everything is perfect from the Hubspot end. It’s Google Analytics where the data is missing, and the only likely explanation is that the onFormSubmit function works sometimes and not others.

I don’t suppose you have any other thoughts? This has happened again since i posted.

Thanks
Garry

0 Upvotes