When a Hubspot form has been successfully validated, Hubspot triggers an event that can be followed to trigger Google Tag Manager tags.
Create a custom HTML tag, paste the code below into the tag's script and use "all pages" as the trigger.
Here is the custom HTML code to paste in the tag:
<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>
You need to create a new trigger for the data layer event triggered by the event listener. This trigger is used to track successfully submitted HubSpot forms.
Finally, create your tag corresponding to the conversion linked to the HubSpot form.
For Appvizer, this will be an HTML tag with the conversion script and as the trigger, the Custom Event above (HubSpot form success).