# Visitor Identification API trouble

**URL:** <https://community.hubspot.com/t/visitor-identification-api-trouble/31661>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [February 11, 2021, 4:22pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661 "2021-02-11T16:22:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GVASSELIN](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gvasselin/32/43872_2.png) [@GVASSELIN](https://community.hubspot.com/u/GVASSELIN)\
**Post date:** [February 11, 2021, 4:22pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/1 "2021-02-11T16:22:15Z")

</div>

Hi,  
I’m trying to integrate the Visitor Identification api with the chat widget on a developer test portal. I followed the related documentation but I’m still unable to make this work properly.  
Here is the thing : I’m able to get a token from the Visitor Identification api, I have set the properties to the chat widget, but when I start a chat conversation then it shows up as “Unknown Visitor”.

My code looks like this :

```lia-code-sample
if (window.HubSpotConversations) {
 onConversationsAPIReady();
}
else {
 window.hsConversationsOnReady = [onConversationsAPIReady];
}

function onConversationsAPIReady() {

 window.hsConversationsSettings = {
 loadImmediately: false,
 identificationEmail: "<EMAILADRESS>",
 identificationToken: "<TOKEN>"
 };
}

function loadChat() {
 window.HubSpotConversations.widget.load();
}

```

So I don’t know what I’m missing or if this kind of issue has already been resolved in another post that I haven’t seen.

I’d appreciate your help thanks.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [February 12, 2021, 7:18pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/2 "2021-02-12T19:18:06Z")

</div>

Hey @GVASSELIN

Are you still struggling with this?

Perhaps @zaklein might be able to help. He has been bringing his A game to the Community 😀

---

<div class="post-metadata">

**Author:** ![zaklein](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zaklein/32/44431_2.png) [@zaklein](https://community.hubspot.com/u/zaklein)\
**Post date:** [February 15, 2021, 12:39pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/3 "2021-02-15T12:39:56Z")

</div>

Hi @GVASSELIN

I might need to get some more information regarding your specific case, but here’s some guidance in the meantime:

In general, I would recommend setting _window.hsConversationsSettings.loadImmediately_ = _false_ **before** loading your HubSpot Tracking Code (assuming you’re already using the JavaScript Tracking Code as part of your chatflow install). For example, with this modification, your HubSpot Tracking Code install script might look something like this:

```lia-code-sample
<!-- Start of HubSpot Embed Code -->
<script>
 window.hsConversationsSettings = {
 loadImmediately: false
 };
</script>

<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/YOUR-PORTAL-ID.js"></script>
<!-- End of HubSpot Embed Code -->

```

Effectively what we’re doing here is ensuring any chatflows that meet a “Target” criteria set in the HubSpot web UI don’t automatically load as the page loads. This gives you an opportunity to identify the visitor using _identificationEmail_ and _identificationToken_ **before** loading the chatflow widget. For example:

```lia-code-sample
window.hsConversationsSettings = {
 identificationEmail: "example@test.com",
 identificationToken: "TOKEN-FROM-API"
};

window.HubSpotConversations.widget.load();

```

I’ve tested this approach and it successfully leads to the visitor being identified in the HubSpot conversations inbox. Hope this points you in the right direction. If not, please provide some more information and I’ll try to help you get to the bottom of it.

All the best,

Zach

P.S. Thanks for the nudge @dennisedson 😄

---

<div class="post-metadata">

**Author:** ![GVASSELIN](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gvasselin/32/43872_2.png) [@GVASSELIN](https://community.hubspot.com/u/GVASSELIN)\
**Post date:** [February 15, 2021, 2:15pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/4 "2021-02-15T14:15:20Z")

</div>

Hey @zaklein ,  
thanks for your reply. I tried your recommandations, but unfortunetly it’s still not working.

What I would like to do is identify users that are logged-in in my web app. Theses logged-in users are also known contacts in hubspot. I want to “automatically” identify them in conversation inbox when they want to use the chat widget, or (if possible) create a lead or a contact when the user is unknown in hubspot, but known in my web app.

To do this I have a developer test portal with 2 known contacts. When I’m logged-in with one or another known contact and start chatting, it show up as “Unknown Visitor”.

Best regards 😀

---

<div class="post-metadata">

**Author:** ![zaklein](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zaklein/32/44431_2.png) [@zaklein](https://community.hubspot.com/u/zaklein)\
**Post date:** [February 16, 2021, 1:05pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/5 "2021-02-16T13:05:13Z")

</div>

Hi @GVASSELIN

It’s unfortunate you’re still having trouble with it. Without seeing it in action, it can be tough to troubleshoot. Is there any more example code you can share and/or an explanation of the sequence of actions your configuration follows? Anything that I can use to try to replicate the problem you’re experiencing would be helpful.

All the best,

Zach

---

<div class="post-metadata">

**Author:** ![GVASSELIN](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gvasselin/32/43872_2.png) [@GVASSELIN](https://community.hubspot.com/u/GVASSELIN)\
**Post date:** [February 16, 2021, 3:20pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/6 "2021-02-16T15:20:14Z")

</div>

Hi @zaklein,

my web app technology is [ASP.NET](http://ASP.NET) with .NET Framework 4.5.

Here is the sequence action :

**Step 1** : After the user logs in, he goes to the live chat page.

**Step 2** : When the page is loading, there is a call to the Visitor identification api to get the token in C# backend (in Page\_Load() method), I only send the email of my contact and get a token.

Notes: I’m always getting a token even it’s an unknown contact and in the hubspot portal, I can see in the call logs it’s working pretty good.

**Step 3 :** The page is generated directly with the token and email here : (this is all the javascript code I have)

```lia-code-sample
<script type="text/javascript">

 if (window.HubSpotConversations) {
 onConversationsAPIReady();
 }
 else {
 window.hsConversationsOnReady = [onConversationsAPIReady];
 }

 function onConversationsAPIReady() {

 var emailAddress = EMAIL-FROM-SERVER-SIDE;
 var token = TOKEN-FROM-SERVER-SIDE;

 window.hsConversationsSettings = {
 disableAttachment: true,
 loadImmediately: false,
 identificationEmail: emailAddress,
 identificationToken: token
 };
 }

 function loadChat() {
 window.HubSpotConversations.widget.load();
 }
</script>
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/YOUR-PORTAL-ID.js"></script>

```

**Step 4 :** the user load manually the widget by clicking on a button with the loadChat() function and start chatting.

For troubleshooting :

I added some console.log() in the script to make sure the email and token are set **before** and **after** loading the chat widget and as far as I can go, it seems to be correctly set.

I tested my app on localhost and on a test server with same result.

I also tried to get a token for a contact and hard written it with email in the chat widget, but same result.

I tried to be in an Incognito or private browsing window with the same result.

I also tried to send firstname and lastname to the api with no success.

Hope this help.

Thanks !

---

<div class="post-metadata">

**Author:** ![GVASSELIN](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/gvasselin/32/43872_2.png) [@GVASSELIN](https://community.hubspot.com/u/GVASSELIN)\
**Post date:** [February 17, 2021, 2:04pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/7 "2021-02-17T14:04:02Z")

</div>

Hey guys !

I still don’t understand why, but know it works. May be a conflict problem with the cookie or something or just with the recommandations of @zaklein.

Anyway thanks you guys for the support !

All the best !

---

<div class="post-metadata">

**Author:** ![SPatel21](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@SPatel21](https://community.hubspot.com/u/SPatel21)\
**Post date:** [May 15, 2023, 6:50am UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/8 "2023-05-15T06:50:14Z")

</div>

@GVASSELIN @zaklein I’m facing the exact issue, I have followed the same doc from hubspot

> **[Accounts Dashboard | HubSpot](https://app.hubspot.com/myaccounts?next=developerdocs&redirect=%2Fapi-reference%2Fconversations-visitor-identification-v3%2Fguide)**

but it still shows unknown visitor in the hubspot inbox.  
I’m using it in Angular SPA. Added the code in app.component

scriptLoader.loadScript(‘hubspot’).then(async () =\> {

```
          const tokenData = await apiService.getHubspotVisitorToken();

          console.log('user', user);

          window\["hsConversationsSettings"] = {

            loadImmediately: false,

            inlineEmbedSelector: 'hubspot-messages-iframe-container',

            identificationEmail: user ? user.email : user.contactEmails\[0],

            identificationToken: tokenData.data.hubspotToken.token

          };

          // Variable for tracking the function's call count

          var onConversationsAPIReady\_call\_count = 0;

          // Define the function which is to be called once the widget is ready

          function onConversationsAPIReady() {

            console.log("2. Executing onConversationsAPIReady()");

            // Test function call count value

            if (onConversationsAPIReady\_call\_count > 0) {

              console.log("4. onConversationsAPIReady() function has already been called, ignoring...");

              return;

            } else {

              // Added a delay to make sure that the widget is cleared only after it's first been initialized. This did not work without the delay as old conversation history managed to load too quickly after page change.

              setTimeout(function () {

                console.log("3. onConversationsAPIReady() first call, about to reset conversations widget and increase call count by 1");

                onConversationsAPIReady\_call\_count = 1;

                window\['HubSpotConversations'].clear({ resetWidget: true });

                console.log("5. Conversations widget was reset and call count increased by 1");

                // Makes HubSpot iframe container visible with a delay

                setTimeout(function () {

                  console.log("6. Conversations widget has been properly reset, so making widget visible");

                  document.getElementById("hubspot-messages-iframe-container").style.visibility = "visible";

                }, 6000);

              }, 500);

            }

          }

          if (window\['HubSpotConversations']) {

            // Call the function

            onConversationsAPIReady();

            console.log("1. onConversationsAPIReady() function call");

          } else {

            // Otherwise, callbacks can be added to the hsConversationsOnReady window object.

            // These callbacks will be called once the external API has been initialized.

            window\['hsConversationsOnReady'] = \[onConversationsAPIReady];

            console.log("1. onConversationsAPIReady() callback");

          }

          // This code handles the Custom Chat provider settings. See the Custom Provider section in our help docs.

        })

      })

    });

```

---

<div class="post-metadata">

**Author:** ![ABoros](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@ABoros](https://community.hubspot.com/u/ABoros)\
**Post date:** [January 25, 2025, 9:51am UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/9 "2025-01-25T09:51:57Z")

</div>

We have a really similar issue:

We have SAAS product, and we are using HubSport as CRM tool. Our site has the HS plugin, but we are only using the chat functionality at the moment.  
We would like to targeting our users with CTAs based on their email addresses after login, and we did the recommended steps by doing the identification via Visitor Identification API, setup the credentials to the js plugin(tracking code snipet)  
we tried with hsConversationsSettings  
and another desperate attempt \_hsq.push([“identify”, { {identity details} }]);  
But still, all the CAT appears only if we set the “Logged in Visitor = false”, and of course the segmented list with specific email addresses doesn’t work either, because it looks like we can not pass the identifiers in the right place.  
I know it’s a bit messy, but any advice would be appreciated!

// Angular FE, Java BE

---

<div class="post-metadata">

**Author:** ![SKomjathy](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@SKomjathy](https://community.hubspot.com/u/SKomjathy)\
**Post date:** [March 25, 2025, 5:06pm UTC](https://community.hubspot.com/t/visitor-identification-api-trouble/31661/10 "2025-03-25T17:06:06Z")

</div>

Thanks for the reply, but I’ve already checked this. I’m making sure in the code that loadImmediately is set to false as soon as possible (as a script in index.html), and all the rest comes only after user authentication is complete:

```lia-code-sample
let onConversationsAPIReady = () => {
 window.HubSpotConversations.widget.load();
}

...

const userData = await getUser()
window.hsConversationsSettings.identificationEmail = userData.email
window.hsConversationsSettings.identificationToken = userData.hubspot_token

if (window.HubSpotConversations) {
 onConversationsAPIReady();
} else {
 window.hsConversationsOnReady = [onConversationsAPIReady];
}

```
