Skip to content

Instantly share code, notes, and snippets.

@justingivens
Last active March 19, 2025 17:30
Show Gist options
  • Save justingivens/d705f1b9d0f8de0dc9303b17ebd68e8d to your computer and use it in GitHub Desktop.
Save justingivens/d705f1b9d0f8de0dc9303b17ebd68e8d to your computer and use it in GitHub Desktop.
HubSpot <> Google Tag Manager Custom Event
//Trigger on pages and customize as needed.
<script>
window.addEventListener('message', function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
dataLayer.push({'event':'hubspot-form-ready','hubspot-form-id':event.data.id});
}
//Form Submission #1
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
dataLayer.push({'event':'hubspot-form-submission','hubspot-form-id':event.data.id});
}
//Popup CTAs
if ( event.data.type === 'hsCallsToActionCallback' && event.data.eventName === 'onCallToActionFormSubmitted' ) {
// Fire your misc tracking code here...
dataLayer.push({'event':'hubspot-form-submission-via-cta','hubspot-form-id':event.data.data.formId});
}
//Booked Meetings
if ( event.data.meetingBookSucceeded ) {
// Fire your misc tracking code here...
dataLayer.push({'event':'scheduled-meeting','hubspot-form-id':event.data.id});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment