If you’ve chanced across this post you may be looking for a way to set up conversion tracking for your Hubspot forms in Google Analytics. Here is a simple way to accomplish this – however the first thing to note is that following method only works if:
If the above 3 conditions apply then the following 5 steps are an easy method to track conversions in Google Analytics.
<script type="text/javascript">
window.addEventListener("message", function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
window.dataLayer.push({
'event': 'hubspot-form-success',
'hs-form-guid': event.data.id
});
}
});
</script>
When done it should look something like this:
Click to save.
When done it should look something like this:
Click to save.
PS. To learn more about Hubspot’s form GUID click here
When done it should look something like this:
Click to save.
When done it should look something like this:
Click to save.
You can now proceed and publish these changes to your GTM container. However, prior to publishing it is always useful to enter “Preview” mode on GTM and then navigate to your page where your form is situated to test. Complete the form and submit – you should see the tags you created in the steps above firing.
For example:
GTM Preview mode – testing form submission
This will allow you to see in Google Analytics whenever the GA Event Tag (that you created in Step 4) fires.
When done it should look something like this:
Click to Save.
If you then go to Google Analytics Live View and then refresh and complete the form again you should have a successful conversion picked up in GA.
Hope that was helpful and that it is all working nicely for you.