APIs & Integrations

marchato
Member

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.

  1. We implemented the snippets as prescribed for Single page APP ([See manual] and snippet placement in the header of the site

  2. We register with the contact form and see the Cookie being dropped as share.hsforms.com.

  3. After step 3 we do register in the hubspot portal as a contact.

  4. We open a Dynalog but do not see the Hubspot Cookie because we do not belong to hsforms domain.

  5. We do fire a Hubspot event after Landing as we can see it in our console.

  6. We do see the page flips in reports but they are not associated with any contacts in the portal.

  7. 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

Thank you,.

Marcel

0 Upvotes
1 Accepted solution
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

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.

View solution in original post

0 Upvotes
2 Replies 2
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

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.

0 Upvotes
marchato
Member

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.

Regards,

Marcel