Adding Action Conversion Pixels To HubSpot Forms

You can set goals to be triggered when the visitor reaches a URL (as a destination goal) or by action conversion. This post is for HubSpot users who need to track goals that can’t be defined according to URL.

1. Go to the “Add Goal/Event” and choose Goal Type: Action conversion

 

2. After clicking the ‘Save’ button, the pixel will be generated:

3.  Copy the code from the <script> tag.

4. Search for the HubSpot form:

4. When using the Form’s embedded code, add this piece of code after the formID line:

onFormSubmit: function($form) {
window.trd_api?trd_api.goal({goalId:1234}):(window.$TRD_goals=(window.$TRD_goals||[])).push({goalId:1234});
}
Notice, the  ‘goalId:___’ should be the same as in the pixel.

 

For example, here is how the embedded code should look like:
<!--[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({
 portalId: "4644841",
 formId: "d77cc949-4163-4e5f-83e3-7c0a8bed21df",
 onFormSubmit: function($form) {
  window.trd_api?trd_api.goal({goalId:1234}):(window.$TRD_goals=(window.$TRD_goals||[])).push({goalId:1234});
 } 
}); 
</script>