UserId used in Tawk_API.login

I am trying to have our already logged in members automatically connected in the Tawk chat widget. I would like the user to be recognised as the same contact in Tawk even if they use a different browser for a later chat rather than a new contact being created. Can I use the userID field (as well as name and email) to ensure the users gets recognised as an existing conatct? If so does this userId need to be unique on your system or just on my Tawk account? Is there an example of he widget code needed for this? Thanks for any help.

1 Like


You’re on the right track! You can definitely use the userId field (along with name and email if available) to identify and connect logged-in members in the Tawk chat widget, even across different browsers.

Here’s a breakdown of your questions:

Using userId for Recognition:

Yes, you can use the userId field to ensure users are recognized as existing contacts in Tawk. By providing a unique identifier that links back to your user database, Tawk can associate past chats and information with the same user.
Uniqueness of userId:

Ideally, the userId should be unique across your entire system, not just within your Tawk account. This ensures consistent identification regardless of where MaryKayInTouch the user logs in. You can use a database ID, user ID, or any other unique identifier associated with your user accounts.
Example Widget Code:

Here’s an example of the widget code with the Tawk API login function to achieve this:


Use code with caution.

Replace YOUR_TAWK_API_KEY with your actual Tawk API key.
Retrieve the user’s userId, name (optional), and email (optional) from your system before including this script.

Populate the visitor object within the tawkApi.init function with the retrieved user data.
This code will automatically attempt to login the user in Tawk using the provided userId.
Additional Notes:

Make sure you have the Tawk API library included in your HTML before this script.
For error handling and advanced features, refer to the official Tawk API documentation:

By implementing this approach, your logged-in members will be recognized as existing contacts in Tawk, providing a more seamless chat experience.

I hope the information may helps you.

Best regards,
Cassie Bratt