APIs & Integrations

sarahjohn388
メンバー

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 いいね!
7件の返信
Fullstackcampus
メンバー

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 いいね!
Derek_Gervais
元HubSpot社員
元HubSpot社員

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
メンバー | Platinum Partner
メンバー | Platinum Partner

Is it possible to add tracking to Hubspot form submit button

How to add event tracking code to hubspot form button ?

0 いいね!
Derek_Gervais
元HubSpot社員
元HubSpot社員

Is it possible to add tracking to Hubspot form submit button

Hi @Roshan,

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

0 いいね!
roshan123
メンバー

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 いいね!
roshan123
メンバー

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 いいね!
danaketh
参加者

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.