Contact API: Single Page App accessing Hubspot Contact Form Cookies
SOLVE
We are trying to integrate Hubspot Tracking into our Single Page Applications written in BackBoneJS, CanJS and ReactJS.
Our goal is to match a user back a hub-spot contact lead when using our Apps on Desktop and Mobile devices.
We implemented the snippets as prescribed for Single page APP ([See manual] and snippet placement in the header of the site
We register with the contact form and see the Cookie being dropped as share.hsforms.com.
After step 3 we do register in the hubspot portal as a contact.
We open a Dynalog but do not see the Hubspot Cookie because we do not belong to hsforms domain.
We do fire a Hubspot event after Landing as we can see it in our console.
We do see the page flips in reports but they are not associated with any contacts in the portal.
We only see the initial page for my contact.
Issue:
How is the HubSpot snippet going to access an external cookie from within the our domain ?
It seems like the Hubspot snippet is not finding the cookie from within our domain to match the user's to a page flip. The obvious reason being is the cross domain nature where where the HubSpot contact form and the our domain have to reside on the same domain.
Does anyone have some code or information on how the Hubspot API matches a Contact when their is no Hubspot hsforms cookie present ?
Any input is greatly appreciate. Please see a more detailed copy of this posting
Contact API: Single Page App accessing Hubspot Contact Form Cookies
SOLVE
Hi @marchato, The cookie that's dropped in a visitor's browser when filling out the form will then be associated with that contact record in HubSpot. You are right in that cookies are only shared on the same domain. That said, if you enable cross-domain tracking here, you should be able to track users between that hsforms domain and your main domain. More info here. Your cross domain linking is currently off. Via the tracking code, you should be using the identify method to identify contacts based on email address: https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor. Keep in mind that the identify function only sets the identities in the tracker. The identities do not get passed to HubSpot until you make a separate trackPageView or trackEvent call.
In order to track views for each page in your single page app, you need to make sure to set the page path for each "page", then call the track page view function push that data to HubSpot as described above.
Instead of using the form "sharing" functionality, you could try embedding the form on the same domain that your single page app lives on so that you wouldn't have to worry about cross-domain linking. This may fix your main issue here.
Contact API: Single Page App accessing Hubspot Contact Form Cookies
SOLVE
Hi @marchato, The cookie that's dropped in a visitor's browser when filling out the form will then be associated with that contact record in HubSpot. You are right in that cookies are only shared on the same domain. That said, if you enable cross-domain tracking here, you should be able to track users between that hsforms domain and your main domain. More info here. Your cross domain linking is currently off. Via the tracking code, you should be using the identify method to identify contacts based on email address: https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor. Keep in mind that the identify function only sets the identities in the tracker. The identities do not get passed to HubSpot until you make a separate trackPageView or trackEvent call.
In order to track views for each page in your single page app, you need to make sure to set the page path for each "page", then call the track page view function push that data to HubSpot as described above.
Instead of using the form "sharing" functionality, you could try embedding the form on the same domain that your single page app lives on so that you wouldn't have to worry about cross-domain linking. This may fix your main issue here.
Contact API: Single Page App accessing Hubspot Contact Form Cookies
SOLVE
Conner,
Thank you so much. You really shed some light on our issue and saved us time researching. This points us in the right direction by orders of magnitudes. We are now continuing our implementation.