APIs & Integrations

sarahjohn388
Member

Is it possible to add tracking to Hubspot form submit button

Hello All,

Does anyone know if tracking code can be added to the submit button in aHubspot form? I've tried adding the tracking code using the onFormSubmit attribute but I'm not getting any tracking results for the submit button clicks. Maybe I have the code incorrectly formatted.? I've included my code below for reference. I've removed the portal and form ids for security reasons.

<!--[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({ 
css: '',
cssClass:'.hs-form fieldset {max-width: 100%;}',
portalId: '',
formId: '',
inlineMessage: '<iframe style="width:100%; height:800px;" scrolling="auto" src="URL goes here"></iframe>',
onFormSubmit: 'mmConversionTag(704048, this, "_self"); ga("send","event","button","click","product distributors")'
});
</script>

Thanks!

0 Upvotes
7 Replies 7
Fullstackcampus
Member

Is it possible to add tracking to Hubspot form submit button

 

nice article.
thanks for sharing with us
<a href="https://fullstackcampus.com/"> full stack course in Hyderabad</a>

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Is it possible to add tracking to Hubspot form submit button

Hi @Roshan,

I believe this is the same issue we're discussing in your other topic:

Alekya
Member | Platinum Partner
Member | Platinum Partner

Is it possible to add tracking to Hubspot form submit button

How to add event tracking code to hubspot form button ?

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Is it possible to add tracking to Hubspot form submit button

Hi @Roshan,

Can you give some more details on your code/setup?

0 Upvotes
roshan123
Member

Is it possible to add tracking to Hubspot form submit button

Hi @Derek_Gervais Sorry the code was not displayed on the above thread i don't know why, I have modified the above thread and added the screenshot of the code.

Thanks!

0 Upvotes
roshan123
Member

Is it possible to add tracking to Hubspot form submit button

Hi,

I have used following script in the GTM but it's not worked for me, could anyone help me to get resolve this issue?

hubspot

Roshan

0 Upvotes
danaketh
Participant

Is it possible to add tracking to Hubspot form submit button

In your case, the error is in the formatting indeed. onFormSubmit has to be a function if I recall right. Therefore this should do the trick:

hbspt.forms.create({ 
  css: '',
  cssClass:'.hs-form fieldset {max-width: 100%;}',
  portalId: '',
  formId: '',
  inlineMessage: '<iframe style="width:100%; height:800px;" scrolling="auto" src="URL goes here"></iframe>',
  onFormSubmit: function() {
    mmConversionTag(704048, this, "_self");
    ga("send","event","button","click","product distributors");
  }
});

We're using GTM for tracking everything. I don't know exactly how ga() works but with GTM our tracking works like this:

At the top of the page, a small script will make sure that dataLayer array is available: window.dataLayer = window.dataLayer || [];
Then anywhere in the code (in this case onFormSubmit event), we just do following:

window.dataLayer.push({
  event: '<EVENT_NAME>',
  formId: '<FORM_ID>'
});

And it works just fine.