How do I identify the logged-in visitor in my site chat?
If your site has a logged-in area, you can tell the chat who the visitor is. Generate the channel secret in the Sharing tab of the chat editor, sign the name and e-mail on your server and call cxLiveChat.identify. The chat stops asking for those details and the contact is merged by e-mail.
Before you start:
- The chat is already embedded in your site. See the Embed code in the same tab.
- You need a server of your own to sign. Never generate the signature in the browser: the secret would be exposed.
Steps
-
Open the chat editor and go to the Sharing tab.
-
In the Identify visitors from your site card, click Generate secret and store the value in an environment variable on your server (for example
CLICKMAX_CHAT_SECRET). -
On the server, compute the signature of the logged-in user: HMAC-SHA256, hex-encoded, of the text
channel ID, line break,e-mail, line break,name, using the secret. -
On the page, set the identity BEFORE the chat script tag (the script loads asynchronously, so
cxLiveChatdoes not exist yet right after it):
If the visitor signs in after the page and the chat already loaded (for example, a login in an SPA), call cxLiveChat.identify({ name, email, signature }).
What you should see
When the chat opens, the visitor goes straight into the conversation, without the name and e-mail form. In the conversation, the contact shows the name and e-mail you sent; if a contact with that e-mail already exists, the conversation joins it.
If something doesn't work
- The chat still asks for name and e-mail. The signature did not match and the chat carries on as an anonymous visitor, with no error shown. Check that the signed text uses the channel ID, e-mail and name exactly as passed to
identify(no extra spaces or different casing) and that the secret belongs to the right channel. - Name or e-mail with a line break. Not accepted: the signature is rejected.
- Generate new secret. The previous secret stops working immediately. Visitors signed with it become anonymous again until your server uses the new one.