Advanced
Send user information to your chatbot for personalized responses and secure identity verification.
You can identify your website visitors to your chatbot, allowing it to provide personalized responses using their name, email, and other information. This is useful for greeting returning users, providing account-specific information, and tracking conversation history.
Use the identify API call to send user information to your chatbot:
(_sitespeak = window._sitespeak || []).push(['onReady', onAI ChatbotReady]);
function onAI ChatbotReady() {
sitespeak.identify('user_332', {
'first_name': 'John',
'nickname': 'J',
'email': 'john@example.com',
'plan': 'Pro',
'account_id': '12345'
});
}
You can send any key-value pairs that are relevant to your use case. The chatbot will use this information as context when responding to the user.
Common fields to include:
first_name
”John”
Personalized greetings
”user@example.com”
Account lookups
plan
”Pro”
100 x 100px
user_id
”12345”
API action lookups
company
”Acme Inc”
B2B context
Your chatbot will automatically use the identified information when it makes sense. For example, if you send the user’s first name, the chatbot might greet them by name.
You can also update your chatbot’s system prompt to explicitly reference this information:
Example system prompt addition:
When responding to users, use their first name if available.
If they ask about their account, use their user_id to look up information.
This results in personalized responses:
The identify call is especially powerful when combined with Custom API Actions. You can use template strings like \{\{user_id\}\} in your API action URLs, and the chatbot will automatically fill in the value from the identified user data.
For example, if you have an API action configured with:
GET https://api.yoursite.com/orders/{{user_id}}
And you’ve identified the user with user_id: '12345', the chatbot will call:
GET https://api.yoursite.com/orders/12345
This allows you to provide account-specific information like order history, subscription status, and more.
This allows you to provide account-specific information like order history, subscription status, and more.
For production applications handling sensitive user data, you should use identity verification to securely authenticate users. This prevents users from impersonating others by sending fake identification data.
In your chatbot dashboard, click Install Agent in the sidebar.
Scroll down to the Identity Verification section.
Enable and Generate Key
Toggle on Enable Identity Verification and click Generate to create your secret key.
const jwt = require('jsonwebtoken');
// Generate a signed token with user data
const token = jwt.sign({
user_id: user.id,
email: user.email,
name: user.name,
exp: Math.floor(Date.now() / 1000) + 3600 // 1 hour expiry
}, 'YOUR_SECRET_KEY', { algorithm: 'HS256' });
window.AI Chatbot.identify({
token: token
});
The chatbot will verify the token signature using your secret key, ensuring the user data hasn’t been tampered with.
When identity verification is enabled, the chatbot widget’s Recent Chats feature follows your users across browsers and devices automatically. A visitor who chatted on their laptop can pick up the same thread on their phone, as long as they are identified with the same user_id.
For unverified visitors, Recent Chats stays local to the browser they chatted from.
No additional configuration is required. As soon as a visitor is identified through window.AI Chatbot.identify({ token }), every conversation they have is linked to their user_id and appears in their Recent Chats list on any device where they are identified with the same user_id.
Here’s a complete example showing how to identify a logged-in user:
Ready to automate your customer service with AI?
Join over 1000+ businesses, websites and startups automating their customer service and other tasks with a custom trained AI agent.