Setting a visitor’s name and email in the Pre-Chat Form using JavaScript API
The instructions below are for desktops and laptops only.
All visitors are assigned a default ID starting with “V” followed by a 16-digit number, like this:
Using the API functions in this guide, you can replace the default ID with the visitor’s name and email address.
There are 2 primary ways to do this:
With hash (recommended for secure data transfers)
Without hash
Note:
Your visitor’s details must be available through your system for the following API functions to work. This means visitors should be logged into your store/website before starting a conversation in your tawk.to live chat widget.
Using a hash can help secure your customers’ data. We employ the HMACSHA256 encryption algorithm to generate a hash.
Important: Enable Secure Mode in your JavaScript API settings before generating the hash.
Here’s a PHP example you can use to generate the hash:
Enter the hash you generated into the hash field of the visitor{} function.
Here’s an example:
If you use a single-page app/website or AJAX logins, enter the hash you generated into the hash field of the setAttributes() function.
Here’s an example:
You can also set the visitor’s name and email address using the visitor{} function without a hash.
Here’s an example:
Additional information
tawk.to’s JavaScript API allows you to automate processes at the beginning or end of a chat. You can learn more about enabling JavaScript API here: JavaScript API
If duplicate contacts are created due to automation, you can merge them into one profile. To learn more about merging contacts, read this article: How to merge contacts
If you have feedback about this article, or if you need more help:
Click the green live chat icon
Schedule a call with us
Visit our community