CMS Development

SHillcoat
Member

Having trouble integrating Google Analytics with Hubspot Form

I am trying to get an on form submit event to work with Universal Google Analytics. We can see the page in analytics but the form isn't firing. Can anyone help?  This is the code I am using: 

 

 hbspt.forms.create ({
region: "na1",
portalId: "xxxxxx",
formId: "0xxx",
onFormSubmit: function($form) {
ga('send', 'event', 'form', 'button', 'contact');
}
});

0 Upvotes
2 Replies 2
Danylo
Member

Having trouble integrating Google Analytics with Hubspot Form

Hey there. We use our own developement - Google Tag Manager tag to track all the needed data and inject them into the non Hubspot form hidden fields (to be still tracked by HubSpot). Thus, you only need to setup a connnector (Zapier does it wrongly) to send event to GA. Btw, if you want to track offline conversions/sales, than GA CID is by far not a single parameter you need to send to GA in order to bypass its filter as well as to send a correct IP (geo) or not a server, but a user.

0 Upvotes
piersg
Key Advisor

Having trouble integrating Google Analytics with Hubspot Form

Hi @SHillcoat, are you using GTM as well as GA? If so, this is a very good guide on how to track Hubspot form submissions in GTM and GA: https://nettlesnet.com/track-hubspot-forms-with-google-tag-manager-analytics/ 

 

If you want to track only a particular form you can add && event.data.id === "[your form ID here]" to the end of the if statement in the form listener tag the instructions have you add, like so:

<script type="text/javascript">
  window.addEventListener("message", function(event) {
    if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted' && event.data.id === "[FORM ID]") {
      window.dataLayer.push({
        'event': 'hubspot-form-success',
        'hs-form-guid': event.data.id
      });
    }
  });
</script>