APIs & Integrations

memcc
Participant

Hubspot LiveChat - Identifying users within Single page apps

SOLVE

Hi there,

 

I am currently working on integrating Hubspot LiveChat into a SPA React web application.  At the moment we are experiencing issues with identifying multiple users across multiple sessions.

 

The issue I have, is that once I include the Hubspot JS, it records the first captured e-mail address as the identity of the end user, with no way of updating. 

 

There are two scenarios that I have come across:

Tracking of non-hubspot forms enabled

1. Enable track non-hubspot forms
2. Include Hubspot js on our index.html

3. Visit the website (which redirects the user to a login form)
4. Attempt to sign in as admin@domain.io with an invalid password
5. Attempt to sign in as user@domain.io with a valid password
6. Open Hubspot chat - within Hubspot, the support agent would see my identity as admin@domain.io, even though I was signed in as user@domain.io.

 

Tracking of non-hubspot forms disabled

1. Include Hubspot js on our index.html

2. Visit the website (which redirects the user to a login form)
3. Attempt to sign in as user1@domain.io with a valid password

4. On successful sign in, we identify the visitor using:

__hsq.push(["identify", { email: 'user1@domain.io' }])

Hubspot docs - Identify a visitor
5. Sign out

6. Sign in as user2@domain.io with a valid password

7. Repeat step 4 with email as user2@domain.io

8. Open Hubspot Chat - the support agent sees my identity as user1@domain.io

 

The only way I have found to get around these issues, is to clear the Hubspot cookies / local storage on every logout.

 

If anyone has any tips or guidance for a better approach to these issues, please post a reply

 

Thanks

Michael

 

1 Accepted solution
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Hubspot LiveChat - Identifying users within Single page apps

SOLVE

I forgot to update this post, apologies.

 

The revokeCookieConsent method now removes the messagesUtk cookie, allowing you to clear live chat identities on the same device. This change has been live since February 21, 2019.

Isaac Takushi

Associate Certification Manager

View solution in original post

0 Upvotes
4 Replies 4
IsaacTakushi
HubSpot Employee
HubSpot Employee

Hubspot LiveChat - Identifying users within Single page apps

SOLVE

Welcome, @memcc.

 

Apologies for the delayed response.

 

I can confirm that the identify function cannot overwrite an existing contact's email address. Here's a similar post I responded to a few months ago. If you do need to overwrite a visitor's email with a new value upon login, you could use this Forms API endpoint.

 

That said, while I was investigating your queries, I found an issue where the messagesUtk cookie (which is separate from the regular hubspotutk cookie) does not get cleared when you call revokeCookieConsent. This can cause issues because when a new hubspotutk cookie is issued (e.g. to a user who logged in with a different email on the same browser), it will copy the value of the messagesUtk cookie of the previous visitor. I'm sharing this discovery with my team and hopefully we'll implement a more robust solution in the near future.

Isaac Takushi

Associate Certification Manager
0 Upvotes
memcc
Participant

Hubspot LiveChat - Identifying users within Single page apps

SOLVE

Hi @IsaacTakushi,

 

No worries - thanks for getting back to me. 

 

This makes sense now, as previously calling removeCookieConsent was still holding on to message state.

 

With regards to identifying our logged in users, would you recommend using the Forms API endpoint instead of the following steps: Hubspot - Identify a visitor docs?

 

Thanks again,

Michael

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Hubspot LiveChat - Identifying users within Single page apps

SOLVE

Hi, @memcc.

 

I just wanted to let you know that the team is going to add the messagesUtk cookie to the revokeCookieConsent method! Once implemented, the live chat modal should not display previous conversations when users log out and you call revokeCookieConsent. I'll update here when that change has been pushed to production.

 

Once this change takes place, I don't see a ton of difference between using the identify method and the Forms API. Since you've already built around the identify method, I might just stick with that. The only thing this function can't do (as I mentioned) is overwrite a user's email address. For that, you would need to use the Forms API.

Isaac Takushi

Associate Certification Manager
0 Upvotes
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Hubspot LiveChat - Identifying users within Single page apps

SOLVE

I forgot to update this post, apologies.

 

The revokeCookieConsent method now removes the messagesUtk cookie, allowing you to clear live chat identities on the same device. This change has been live since February 21, 2019.

Isaac Takushi

Associate Certification Manager
0 Upvotes