Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fbonawiede/556499ea3c0a0a3ae831f7d29e6a309f to your computer and use it in GitHub Desktop.
Save fbonawiede/556499ea3c0a0a3ae831f7d29e6a309f to your computer and use it in GitHub Desktop.
Track conversions of Hubspot Meetings (iframe)
function isHubspotUrl(url) {
var hubspotUrls = [
'https://local.hubspot.com',
'https://app.hubspotqa.com',
'https://app.hubspot.com',
'https://meetings.hubspot.com'
];
return hubspotUrls.indexOf(url) > -1
}
// hubspot meetings uses postMessage api to send various events
function receiveMessage(event) {
if (isHubspotUrl(event.origin) && event.data.meetingCreated) {
// Fire your misc tracking code here...
// Console printout for debug
console.log('hubspot meetings: meetingCreated event');
// Segment tracking
analytics.track('Meeting Booked');
}
// There was a typo in the event fired by hubspot previously, spelling the attrubute 'meeetingBookSucceeded`.
// This has been fixed!
if (isHubspotUrl(event.origin) && event.data.meetingBookSucceeded) {
// Fire your misc tracking code here...
// Console printout for debug
console.log('hubspot meetings: meetingBookSucceeded event');
// Segment tracking
analytics.track('Meeting Booked');
}
}
window.addEventListener('message', receiveMessage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment