👤 Passing User Data to Ainisa
Ainisa allows you to send your users’ data (like ID, name, or email) to your AI Assistant for personalization — such as recognizing logged-in users, retrieving their orders, or saving chat history.
This feature is available starting from the Pro plan.
🔐 1. Find Your Secret Key
Each user (business) has a unique Secret Key used to generate a secure hash for identifying their users.
You can find your Secret Key in your Business Dashboard → Chat Widgets → Get Widget Code (for any widget) page.
⚠️ Important: Never share your secret key publicly or expose it in frontend code!
🧱 2. Add User Data Script
Before the Ainisa widget script (widget.js), you must include this JavaScript block inside your website pages.
<script>
const userId = 'YOUR_USER_ID'; // Optional, your own user's ID
const userHash = 'YOUR_USER_HASH'; // Optional, must be created with your secret key
const userFirstname = 'YOUR_USER_FIRST_NAME'; // Optional, your own user's firstname
const userLastname = 'YOUR_USER_LAST_NAME'; // Optional, your own user's lastname
const userEmail = 'YOUR_USER_EMAIL'; // Optional, your own user's email
window.ainisaUser = {
user_id: userId,
firstname: userFirstname,
lastname: userLastname,
email: userEmail
};
</script>Then include:
<script src="https://chatbot.ainisa.com/widget.js"></script>🧮 3. Create the User Hash (Required for Secure Identification)
You must create the user_hash in your server-side code, not in the browser.
It’s generated using your user’s ID and the Secret Key Ainisa provides.
Example (JavaScript, Node.js):
const crypto = require('crypto');
const userId = '1'; // must be string
const secretKey = 'your_secret_key_here'; // from Ainisa
const hmac = crypto.createHmac('sha256', secretKey).update(userId).digest('hex');
//Result (example):
console.log(hmac);
//Output:c82448e627ac6d4bbdfcbe8720513a6f2052fbaa5c0386867f8a9e8def656627🧠 The hash must be stored in your own users table, e.g., as a
user_hashcolumn next to your user data.
Ainisa uses this hash to verify the authenticity of user data when it’s sent via the widget.
⚙️ 4. Laravel Example Integration
If your website runs on Laravel, you can dynamically inject your authenticated user’s data into the widget.
<script>
const userId = '{{ auth()->user() ? auth()->user()->id : '' }}';
const userFirstname = '{{ auth()->user() ? auth()->user()->firstname : '' }}';
const userLastname = '{{ auth()->user() ? auth()->user()->lastname : '' }}';
const userEmail = '{{ auth()->user() ? auth()->user()->email : '' }}';
const userHash = '{{ auth()->user() ? auth()->user()->user_hash : '' }}';
window.ainisaUser = {
user_id: userId, // optional
user_hash: userHash, // optional
firstname: userFirstname, // optional
lastname: userLastname, // optional
email: userEmail // optional
};
</script>
<script src="https://chatbot.ainisa.com/widget.js"></script>When a logged-in user opens the chat, Ainisa automatically receives their profile data and can personalize responses.
🔄 5. How It Works
- You create and store a
user_hashfor each user using your secret key. - When your user visits the site, your frontend injects the user data + hash before loading the widget.
- Ainisa verifies the hash and securely associates that chat session with the correct user.
- The data is sent through the Ainisa API for context in AI responses.
⚠️ Privacy Notes
- Always mention in your Privacy Policy / GDPR section that you share user data (if any) with Ainisa.
- Never send user data without your users’ explicit consent.
- The
user_hashensures that Ainisa cannot impersonate or spoof users without your secret key. - Don’t include sensitive data (like passwords or tokens).