How to identify a contact in the chat?

Highlighted
Occasional Contributor

Hi,

how can I identify a visitor in the chat box? I've tried the identify API

 var _hsq = window._hsq = window._hsq || []; 
_hsq.push(["identify", { email: "${email}" }]);

but it didn't work. New chat conversations still appear as "Uknown Visitor"

I'd appreciate your help.

Thanks,
Lukasz

Reply
0 Upvotes
26 Replies 26
New Member

Hi Lukasz,

I am having the exact same issue.
I'm interested if you found a solution !

Thanks,
Romu

Reply
0 Upvotes
Community Manager

Hi @LukaszWiktor and @Romusc,

The "identify" method of the Tracking Code API only stores the identity information in the tracker; you'll need to call the "trackEvent" or "trackPageView" method to actually pass the identity info to HubSpot. Are you both subsequently calling one of these events?

Reply
0 Upvotes
Occasional Contributor

Hi @Derek_Gervais,

Thanks for the hint! I was only calling identify. Now, I added trackPageView right below but it still didn't help. My code snippet looks like this:

<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/1234567.js"></script>
<script>
    var _hsq = window._hsq = window._hsq || [];
    _hsq.push(["identify",{
         email: "user@example.com",
    }]);
    _hsq.push(["trackPageView"]);
</script>

I have this user already in my Contacts but when they start a chat conversation then it shows up as "Unknown Visitor" :frowning:

Reply
0 Upvotes
Community Manager

Hi @LukaszWiktor,

Is this true even after a page refresh? My gut tells me that the contact identification is working, but the messages client isn't being updated with the identity info. Can you try making the association, then refreshing?

Reply
0 Upvotes

Hiii
I have same issue but after refreshing it's identified in chat conversation. I have SPA in Angular 5. Any other solution for Why should i have to refresh.??

Reply
0 Upvotes
New Member

Hi
I have the same issue

<!-- Set up the path for the initial page view -->
<script>
    var _hsq = window._hsq = window._hsq || [];
    _hsq.push(["identify",{
        email: '{{ app.user.email }}',
        id: '{{ app.user.id }}'
    }])
    _hsq.push(["trackPageView"]);
</script>

<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/portal_id.js"></script>
<!-- End of HubSpot Embed Code -->
Reply
0 Upvotes
New Member

Did you find any solution?

Reply
0 Upvotes
New Member

No,
it is not possible.

The chat and analytics are two different systems and they don't communicate each other.

I had to use another chat provider :frowning:

Reply
0 Upvotes
New Member

Hi!

Could you tell me which chat provider you use?

Reply
0 Upvotes
Occasional Contributor

Hello, we have the exact same issue. We want to identify the conversations, but instead we only get "Unknown Visitor".

Any solution for this ?

Reply
0 Upvotes

Any updates on this?

My problem is that I need to re-identify my users upon logout / another login, but it seems that the first identify is stucked, and when the chat widget opens, the previous history shows up, and the messages goes in the name (email) of the first identified user no matter if I call again the window._hsq.push([ "identify", { email: .. } ]). What is the proper way to re-identify the chat so I could handle my single page app logout/login process?

Reply
0 Upvotes
New Member

@Derek_Gervais I'm using Forms API to submit hubspotutk along with contact name/email/ip upon login, yet I still need to refresh for the contact to be recognized by the bot.

When the user was just logged in for the first time, it's still considered an unknown visitor by the bot, and simply one more refresh would solve the issue. It has nothing to do with timing, I tried dynamically loading the script 10 seconds after the page was fully loaded upon login but I still had to refresh one more time to have the bot recognize the contact.

Visitor

Was there ever a solution on this? we have the same problem, visitors are identified as unknown until refresh the page we only want to show chat to people in a targeted segment, so need to know who they are and not hope that they refresh the page, on a single page application

New Contributor

We are also having issues with this and are using Segment. Are there any solutions? Surely this is a critical requirement?

Reply
0 Upvotes
HubSpot Moderator

Hey all, we recently came out with a Conversations JavaScript API, where you wouldn't have to refresh the page. This is great for SPAs because now you can just refresh the widget and not the page itself. After some quick testing on a page of my own, I was able to identify the contact, refresh the widget programmatically, then have the ability to see the contact's email address within the Conversations tool. 

screenshot: http://prntscr.com/nvwptt

We still can't use personalization tokens inside the chat unless you're using bots, but now the contacts you identify won't show up as "Anonymous Visitor". Here's the code I used:

function onConversationsAPIReady() {
    var _hsq = window._hsq = window._hsq || [];
    console.log("ready")
    _hsq.push(["identify",{
    	email: "test@testing.com"
}]); _hsq.push(['trackPageView']); setTimeout( () => { console.log("refresh") window.HubSpotConversations.widget.refresh(); }, 1000) } function sendIdentify(){ if (window.HubSpotConversations) { onConversationsAPIReady(); } else { window.hsConversationsOnReady = [onConversationsAPIReady]; }

feel free to keep testing, but just wanted to make sure you were aware of this new JS API we have.

 

New Contributor

@cbarley Thanks for your precious feedback!

I've been spending the last few hours on this but I'm still having issues in using the refresh API.

I'm using the exact same code you posted; I also verified that things are lined up just fine temporally (the sequence of events is correct: once the hsConversation API is ready my code pushes the "identify" value and the "trackPageView" into _hsq and then calls the refresh function).

Though, nothing happens, my user is still "unknown" to HubSpot (even though I've provided id and email matching one of my contacts). 
Similarly, if I setup the Chatflow to show only for tracket contacts, the widget never shows, even though I provide the id and email of the contact before calling refresh.

I still need to do a hard reload of the page to see the widget popping up. Smiley Sad

This is the code I run (in a simplified version, without setTimeout and fake data):

window._hsq = window._hsq || [];
window._hsq.push([
  "identify",
  { email: "email@example.com" }
]);
window._hsq.push(["trackPageView"]);

window.HubSpotConversations.widget.refresh();

Nothing happens when I do that. 

What I noticed is that when this happens I find the following response for the network request issued by your code to the url:  https://api.hubspot.com/livechat/v1/message/public?portalId=XXXXX&...&mobile=false&messagesUtk=YYYY

{"@type":"HIDE_WIDGET","type":"HIDE_WIDGET","metadata":{"@type":"HIDE_WIDGET_META","reason":"NO_MATCHING_WELCOME_MESSAGE","description":"No matching welcome message for portal XXXXX page http://localhost:3000/mypageurl or visitor does not match targeting rules"}}

Might this be linked to the widget not refreshing as intended?

Ah, one additional thing:

 

I noticed that if I open my contact detail page in HubSpot, I correctly see ALL the "trackPageView" events I pushed! 
Even though the chat widget keep not recognizing the user (unless I refresh the page), the "trackPageView" event I push seems to correctly reach HubSpot and map to the correct contact!

 

Reply
0 Upvotes
HubSpot Moderator

Hi @damdam , the contact's name or email can't show inside the chat bubble since personalization tokens aren't able to be used in that setting, but if you identify the contact, you should be able to see in the Conversations Tool inside HubSpot that they aren't an Unknown Visitor anymore. 

 

The weirdness of that behavior you're seeing right now could also be because you're testing on localhost. I've seen strange behavior there so you should probably just test out on an unpublished test page in HubSpot.

Reply
0 Upvotes
New Contributor

Hi @cbarley , thanks for the quick reply!

I'm aware of the issue with the personalization token Smiley Happy 
That's not what I was talking about. My problem is exactly what you guessed: in HubSpot the visitor is not recognized as a contact and shows up as "Unknown visitor" (until I refresh the browser page that is, from that moment onward it is properly recognized).

I honestly don't see why using localhost might be a problem, since there's no mention of any domain in Hubspot (so HubSpot wouldn't be able to apply any special behaviour depending on the URL of the incoming request); if that was the case, I would expect the visitor not to be recognized, ever, not even after a page refresh (and that is not the case).

 

I'll try connecting through a tunnel (to proxy my localhost address through a public address) and see if there's any difference but I won't hold my breath on this.. I've a feeling that it won't change that much.

 

I'll keep you posted Smiley Happy

Thanks again for the prompt feedback, much appreciated!

Reply
0 Upvotes
New Member

Can confirm that it doesn't work on localhost which definitely caused some confusion. Example works in production.

Reply
0 Upvotes
New Contributor

Hi, 

 

I'm trying to follow your example but it seems some of your code is missing. How do you utilize the call to sendIdentify()?

 

Thanks!

Reply
0 Upvotes
New Contributor

This is worked for you since you have used email "test@testing.com". JUst change it to something else and it won't work.

Reply
0 Upvotes
Regular Contributor

Hey @Madura , I tested with a real email address and it worked again with the exact code above. You just need to 1. push the data into the tracking code by using an identify call 2. call a trackPageView or trigger an event to send that data to HubSpot 3. Refresh the widget immediately and the user can then chat. This will identify the contact inside of the Conversations Tool inside of HubSpot. Not totally sure about identifying the user within the literal chat widget, but I just might not have tested enough. It seems like it should be possible though

Reply
0 Upvotes
Visitor

@cbarley Thanks much for this info.  I'm new to HubSpot (and Javascript) so I don't have a strong foundation, but I could really use some clarity around how this works. I believe my problem matches this thread topic: We're using the HubSpot Conversations API, and we're having conversations show up as Unknown Visitor. My issue is not that it doesn't work, it's that it's not reliably working. We have a SPA React app and we're following the instructions on this page, and we often get a contact associated with the name, but frequently we don't. What we're seeing is:

 

* When opening an incognito window and logging in for the first time, we get Unknown Visitor about 20% of the time.
* After logging out of our app then logging back in, we get Unknown Visitor 100% of the time. Logging out and logging back in again will usually resolve it, although sometimes the name received in HubSpot is actually the previous login, not the current one.

 

When the identity changes, we push the new identity and trackPageView per this thread.
When the location changes, we setPath and trackPageView.
When the user logs out, we revokeCookieConsent and trackPageView, then clear the converation, refresh the widget and reload the page.

 

I've removed as much uncertainty as I can: Everything going to hubspot is serialized, has a widget refresh after each operation, and only runs the next operation once the refresh (or reload) is finished. I've verified we're sending the correct email and the events are in order. As far as I know the tracking code is being triggered and it's always sending the correct email (I assume https://track.hubspot.com/__ptq.gif is the tracking URL, that's where I'm seeing the identity attached).

 

Everything looks good, and more importantly, everything seems to be the same every time, but it's just random whether or not we'll get an Unknown Visitor. Is there any insight in to how this works?

Visitor

Hi,

 

On our platform all visitors must be logged in which means that for all connexions we have their email address and they are registered in our Hubspot CRM.

 

I am wondering why there is no feature in the Conversations API that enables to push throught the visitor email address while the chat is loading? So, if the visitor starts a conversation we can identify him in Hubsport and/or Slack or whatever other tool we are using to engage with him.

 

It would be much easier than using cookies and three different APIs (from what I've understand from technical documentation and from this thread). But I might have missed something... is there any feature in the Conversations API where we could post the visitor's email address each time the chat loads to make sure to identify him if he engages the conversation?

 

Thanks,

Reply
0 Upvotes
New Contributor

Hello @cbarley. Can you send us the HTML example page working identifying a visitor by email?

 

We are using your example code snippet but didn´t work.

 

Reply
0 Upvotes
Regular Contributor
Reply
0 Upvotes