Identifying users and triggering events using HubSpot

Requirements before proceeding.

In general, to understand how to identify visitors and to trigger events, please visit: How to set journey properties in JS

We'll further assume the following:
website: site.com
www website is supported! www.site.com
Advanced URL is track.site.com
https is supported!


Adding the snippet to the page to record the page view and initiate the journy() function

Add the following code on top of the <body section> of your form page:

<script src="https://track.site.com/tracker.js" async></script>
<script>
window.journy=window.journy||function(_,n,o){window.__journy_queue__||(window.__journy_queue__=[]),window.__journy_queue__.push({command:_,args:n,date:Date.now(),callback:o})};
journy("init", { trackerId: "**your-journy-ID**", domain: "https://track.site.com" });
journy("pageview"); /*record the page view! */
</script>


You'll need to change your-journy-ID to your. actual journy-ID, and your Advanced URL to your own as well.
But the simplest way is to copy-paste the whole code from your journy.io business setting menu.

Identifying visitors and/or triggering event when submitting Instapage forms.

Add the following code in the <Footer section> of your form page:

<script>
window.addEventListener('message', event => {
if (
event.data.type === 'hsFormCallback' &&
event.data.eventName === 'onFormSubmit' &&
Array.isArray(event.data.data)
) {
journy("event", { tag: "HubSpot-Form-Submit" });
var emailField = event.data.data.find(function(field) {
return field.name === "email";
});
if (emailField) {
journy("identify", { email: emailField.value });
}
}
});
</script>


You need to set the page recording snippet before being able to identify a visitor or trigger an event!
Was this article helpful?
Cancel
Thank you!