icon-people 7 days of no-limit free trial. Try now! icon-people
en
ru

Transferring customer data from online chat

If a client is authorized on a website or in a mobile application where a Chat2Desk widget or SDK is used, the site can receive and transmit the session identifier clientKey. It allows determining that the dialog is conducted with a particular client, when he or she first contacts the online chat. Similarly, you can pass information about the client to his client card in Chat2Desk.

Obtaining and storing the identifier will help to identify the client in the future, and the system will not create a separate chat when it is accessed. However, a second transmission of the identifier will be needed when the customer is contacted again. This will also make it easier to keep the correspondence history in one chat.

Please note that it is not necessary to transfer the identifier each time. Chat2Desk will create a new chat only if the client resets cookies on the website or when reinstalling the mobile application.

What data can be transferred:

  • ID,
  • name,
  • phone number,
  • comment,
  • custom fields.

To pass this information, the following methods must be added to the widget or SDK code:

Receiveing clientKey

Thanks to clientKey it is possible to store the client's session ID, which allows to continue correspondence in the same dialog

<script>
  document.addEventListener('initialize_widget', (event) => {
    console.log('clientKey:', event.detail.clientKey)
  })
</script>

Transmitting clientKey to online chat

<script>
  document.addEventListener('before_initialize_widget', () => {
    const chat24 = document.querySelector('#chat24-root chat-24')

    chat24.setClientKey("clientKey")
  })
</script>

Obtaining a list of custom fields

<script>
  document.addEventListener('initialize_widget', () => {
    const chat24 = document.querySelector('#chat24-root chat-24')

    console.log('CustomFields', chat24.getCustomFields())
  })
</script>

Transferring data via the online-chat API

<script>
  document.addEventListener('initialize_widget', () => {
    const chat24 = document.querySelector('#chat24-root chat-24')
    
  /**
   *
   * @param name: string | undefined Client name
   * @param phone: string| undefined Client phone
   * @param customFields: {[key: number]: string} List of values for custom format fields 
   * key: value, where key is the custom field ID

   */
    chat24.sendClientInfo({
      name: 'Client name',
      phone: 'Client phone',
      customFields: {
        [fieldId]: fieldValue
      }
    })
  })
</script>

Related articles