Forked from thmsobrmlr/hubspot-meetings-conversion-tracking.js
Created
October 26, 2018 14:37
-
-
Save timelf123/550d9fa29e7f21b507f20ebeb89efcb6 to your computer and use it in GitHub Desktop.
Track conversions of Hubspot Meetings (iframe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
console.log('hubspot meetings: meetingCreated event'); | |
} | |
// there is a typo in the event fired by hubspot. `meeetingBookSucceeded` is the correct attribute to watch for. | |
if (isHubspotUrl(event.origin) && event.data.meeetingBookSucceeded) { | |
console.log('hubspot meetings: meeetingBookSucceeded event'); | |
} | |
} | |
window.addEventListener('message', receiveMessage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment