Live chats > Create an online LiveChat for your website / Automatic authentication in LiveChat

Automatic authentication in LiveChat

Configure automatic user authentication in LiveChat. Then, after authentication on a website or portal, the user will not have to fill out another authentication form in LiveChat to start correspondence with an operator.

The setting also allows you to save the correspondence history if the user sign in the website from another device or browser.

To do this:

  1. Set the prohibition to manually fill in the data for authentication in the chat. For this, go to LiveChat settings and uncheck all the checkboxes in the option User authentication fields.
  2. Go to the website or portal page settings, open the code text for the LiveChat embedding, and add the elma365LiveChatProfile attribute to it using the following parameters with the String data type:
    • id. The user ID;
    • hash. The hash key for user authentication;
    • name. The user’s name;
    • email. The user’s email address;
    • phone. The user’s phone number.

Code example:

elma365LiveChatProfile=’{"id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "hash": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "name": "User name", "email": "email@email.ru", "phone": "+79999999999"}’

Here is an example of using the elma365LiveChatProfile attribute to embed LiveChat on a portal page:

  1. Open the portal page that contains LiveChat in the interface designer. Click the Context tab and create a user_data variable to store user data.
  2. Go to the Scripts tab and add code to the onInit function that will store user data in the user_data variable in string format:

const user = await System.users.getCurrentUser();
const HASH_KEY = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
Context.data.user_data = JSON.stringify({
      id: user.data.__id,
      hash: HASH_KEY,
      name: user.data.__name,
      email: user.data.email ?? ' ',
      phone: user.data.phone ?? ' '
});

  1. Go to the Template tab and open the settings for the Code widget that is added to embed LiveChat. In the code text,  to the elma365LiveChatFormId attribute, add the elma365LiveChatProfile attribute with the user_data variable:

<script>
  let loader = document.querySelectorAll('[src="https://domain.elma365.ru/assets/livechat/assets/elma365.livechat.loader.js"]')[0];
  loader.setAttribute('elma365LiveChatFormId', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
  loader.setAttribute('elma365LiveChatProfile', '<%= Context.data.user_data %>');
</script>

  1. Save and publish the changes of the portal page template.

Found a typo? Highlight the text, press ctrl + enter and notify us