For AI agents: the complete documentation index is available at https://docs.clickmax.io/en/llms.txt, the full documentation bundle is available at https://docs.clickmax.io/en/llms-full.txt, and this page is available as Markdown at https://docs.clickmax.io/en/features/messaging/identify-visitors-in-site-chat.md.
  • English
  • 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

    1. Open the chat editor and go to the Sharing tab.

    2. 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).

    3. 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.

      import { createHmac } from 'node:crypto';
      
      const signature = createHmac('sha256', process.env.CLICKMAX_CHAT_SECRET)
        .update(`${channelId}\n${user.email}\n${user.name}`)
        .digest('hex');
      $signature = hash_hmac(
        'sha256',
        "$channelId\n{$user['email']}\n{$user['name']}",
        getenv('CLICKMAX_CHAT_SECRET')
      );
    4. On the page, set the identity BEFORE the chat script tag (the script loads asynchronously, so cxLiveChat does not exist yet right after it):

      <script>
        window.cxLiveChat = { identity: { name: user.name, email: user.email, signature } };
      </script>

    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.