What is the correct way to implement the Chat?

Occasional Contributor

Hi folks,

i've read here and tested and changed my code several time, but setting the identity works not 100% of our cases.

The code is 

after login 

  static setChatIdentity = (email) => {
    if (window.HubSpotConversations) {
      this.onConversationsAPIReady(email);
    } else {
      window.hsConversationsOnReady = [this.onConversationsAPIReady(email)];
    }
  }

  static onConversationsAPIReady = (email) => {
    console.log("onConversationsAPIReady", email);
    setTimeout(() => {
      var _hsq = window._hsq = window._hsq || [];
      //_hsq.push(["doNotTrack"]);
      //_hsq.push(['doNotTrack', {track: true}]);
      //_hsq.push(["setPath", "/chat"]);
      //window.HubSpotConversations.clear();
      //_hsq.push(["revokeCookieConsent"]);
      _hsq.push(["identify", {
        email: email
      }]);
      _hsq.push(["trackPageView"]);
      //window.HubSpotConversations.widget.refresh();
      //window.HubSpotConversations.on("conversationStarted", payload => {
      //_hsq.push(["doNotTrack"]);
      //});
      setTimeout(() => {
        console.log("refresh", email)
        _hsq.push(["identify", {
          email: email
        }]);
        _hsq.push(["trackPageView"]);
        window.HubSpotConversations.widget.refresh();
      }, 2000);
    }, 1000);
  }

Most of the time, this is working, but that's not enough. And i have no idea, what i must do, to make this more stable.

Has somebody another hint for me?

Reply
0 Upvotes
2 Replies 2
Highlighted
HubSpot Moderator

Hey @stundzigs ,

 

I can totally apreciate your frustration here; based on the description in your post, it sounds like this is behaving as expected. The follow forum post written up by Isaac goes in depth around the nuts and bolts of how the Chat Widget interacts with Visitor Identities. If you have any questions around this that aren't answered in the following post, let me know!

 

https://community.hubspot.com/t5/APIs-Integrations/Identify-a-contact-in-a-chat-widget/m-p/272410#M2...

Reply
0 Upvotes
Highlighted
Occasional Contributor

Hi Derek,

 

actually i'm waiting for the fix in your chat implementation. Hopefully this is coming till the end of this month. Is it?

 

Regards

   Steffen...

Reply
0 Upvotes