Quick Start
Identify a user when they log in:Identity Object
The identity object has two parts:User ID
TheuserId should be your internal identifier for the user:
User Metadata
Pass any properties that help personalize the experience:How Identity Is Used
1. Conversation Linking
Conversations are linked to the user ID, allowing:- History continuity — Users see their past conversations across devices
- Agent context — The agent knows who they’re talking to
- Analytics — Track conversations per user in your dashboard
2. Form Pre-filling
Forms automatically use metadata to pre-fill fields when the field name exactly matches a key inuserMetadata:
Field names must exactly match the keys in
userMetadata. For example, a field named user_email will only be pre-filled if you have userMetadata.user_email, not userMetadata.email.3. Agent Personalization
The agent receives user metadata and can use it in responses:For security, sensitive fields are automatically excluded from the agent’s context. Fields containing tokens, passwords, secrets, API keys, or credentials are filtered out. See Personalized Responses for details.
4. Dynamic Form Schemas
Form schema providers receive user context:5. HTTP Tool Authentication
Identity data can be passed to HTTP tools for authenticated API calls. This is useful when your tools need to access user-specific data from your backend.{{userId}} and {{userMetadata.path}} placeholders are replaced with the user’s identity data at runtime.
See HTTP Tools - User Context Variables for complete documentation on this feature.
6. Personalized Responses
The agent receives sanitized user context to personalize its responses. This enables greetings, contextual answers, and tailored recommendations based on user data.Initial Message Templating
The widget’s initial message supports template variables:Template Syntax
If a field is undefined, it renders as an empty string.
Security: Excluded Fields
To protect sensitive data, certain fields are automatically excluded from the agent’s context. Fields with keys matching these patterns (case-insensitive) are filtered:tokensecretpasswordapikey/api_keyaccesstoken/access_tokenrefreshtoken/refresh_tokenauthcredentialprivate
Implementation Patterns
On Login
On Logout
React Context
Next.js App Router
Vue Composition API
Visitors vs Users
Ansa tracks two types of identities:Getting Visitor ID
- Generated automatically on first visit
- Stored in localStorage
- Persisted until cleared
- Unique per browser/device
Linking Visitors to Users
When a visitor logs in, their anonymous conversations become linked to their user account:Privacy Considerations
What to Include
- Name, email (for personalization)
- Account type, plan (for context)
- Preferences (for customization)
- Non-sensitive IDs
What to Avoid
- Passwords or secrets
- Full credit card numbers
- Social security numbers
- Health information
- Any data you wouldn’t want logged
GDPR Compliance
If a user requests data deletion:- Use the API to delete their conversations
- Their identity data is automatically cleared
- Consider calling
clearIdentity()to clear client state
SDK Usage
The SDK provides the same identity functions:Debugging
Check the current identity state in the console:Best Practices
- Use stable IDs — Don’t use session IDs or emails as
userId - Keep metadata current — Update when user profile changes
- Reset on logout — Always call
resetUser()when signing out - Be selective — Only pass metadata you’ll actually use
- Match field names — Use standard names for automatic form pre-fill
Next Steps
Triggering Forms
Pre-fill forms with user data
Webhooks
Send user data to external systems