Sales Hub Onboarding

KReimer
Member

Sent an event to Google Analytics when embedded meeting form is submitted

SOLVE

Hi, everyone!

I am looking for a way to send events to GA, when embedded meeting form is submitted on my landing page. It will allow me to send events to FB & Google ADs accounts to train performance campaigns. Unfortunately, I couldn't find any doc on how to implement this. This article is on a similar topic, but it applies only to "Marketing - Forms" tool, which doesn't have the required time booking option. https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options?_ga=2.208428626.1790481021.1...

Could you help me to find a way to capture form submission from the meeting iframe on an external site?

0 Upvotes
1 Accepted solution
KReimer
Solution
Member

Sent an event to Google Analytics when embedded meeting form is submitted

SOLVE

<script>
window.addEventListener( 'message', function(event) {

// Note, you need to have the meeting scheduler embedded on a page where this event listener is also active. Take a look at the domain of the iframe the scheduler is embedded through and make sure it matches this conditional check.
if ( event.origin != 'https://meetings-eu1.hubspot.com' )
return false;

// You'll need our GTM base code installed so that this dataLayer push triggers events to various platforms.
if ( event.data.meetingBookSucceeded ) {
window.dataLayer.push({
event: 'hubspot_meeting_booked'
});
console.log('hubspot_meeting_booked');
}

});
</script>


The script above worked for me! Found it here:

 

https://community.hubspot.com/t5/Reporting-Analytics/Tracking-booked-meetings-through-Google-Tag-Man...

View solution in original post

0 Upvotes
2 Replies 2
MrJustinGivens
Top Contributor | Gold Partner
Top Contributor | Gold Partner

Sent an event to Google Analytics when embedded meeting form is submitted

SOLVE

Hey @KReimer, if you want to trigger other events to Google Analytics here's the code for all three (embed form submissions, landing page submissions and embed meetings):

 

<script>
    window.addEventListener('message', function(event) {
        //Form Submission #1
        if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
            dataLayer.push({'event':'hubspot-form-submission','hubspot-form-id':event.data.id});
        }
        //Form Submission #2
        if(event.data.accepted && event.data.formGuid) {
            dataLayer.push({'event':'hubspot-form-submission','hubspot-form-id':event.data.formGuid});
        }
        //Booked Meetings
        if ( event.data.meetingBookSucceeded ) {
            // Fire your misc tracking code here...
            dataLayer.push({'event':'scheduled-meeting','hubspot-form-id':event.data.id});
        }
    });
</script>

 



Justin Givens


HUG Leader & Community Champion


Resident HubSpot Nerd | Image in a Box


 
 
 


mobilePhone
(256) 886-8269 | (256) 434-5877

emailAddress
justin@imageianbox.com

website
imageinabox.com

 
Schedule a time to talk

website
Let's connect on LinkedIn
 
 

 









0 Upvotes
KReimer
Solution
Member

Sent an event to Google Analytics when embedded meeting form is submitted

SOLVE

<script>
window.addEventListener( 'message', function(event) {

// Note, you need to have the meeting scheduler embedded on a page where this event listener is also active. Take a look at the domain of the iframe the scheduler is embedded through and make sure it matches this conditional check.
if ( event.origin != 'https://meetings-eu1.hubspot.com' )
return false;

// You'll need our GTM base code installed so that this dataLayer push triggers events to various platforms.
if ( event.data.meetingBookSucceeded ) {
window.dataLayer.push({
event: 'hubspot_meeting_booked'
});
console.log('hubspot_meeting_booked');
}

});
</script>


The script above worked for me! Found it here:

 

https://community.hubspot.com/t5/Reporting-Analytics/Tracking-booked-meetings-through-Google-Tag-Man...

0 Upvotes