How to Track Conversion on HubSpot Embedded Forms
If you're using HubSpot's embedded forms on your website and want to track named conversions with Oktopost, you will need to use a slightly different implementation as described in this article.
First, make sure to install the Oktopost Tracking Code on your website.
Next, copy the form embed code from HubSpot and edit it, like so:
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
portalId: "ACCOUNT_ID",
formId: "FORM_ID",
onFormSubmit: function (form)
{
_oktrk('send', {
tag: 'TAG_NAME',
firstName: form.find('input[name="firstname"]').val(),
lastName: form.find('input[name="lastname"]').val(),
email: form.find('input[name="email"]').val()
});
}
});
</script>
Replace the TAG_NAME with the conversion type you want to track and that's it. That will send Oktopost the conversion details once a user completes the form.