Browse docs
Identify your users
Pass signed-in users to the Axoryn widget with identify(), prove who they are with an HMAC user_hash from your server, and reset on logout.
This page is for developers whose site has signed-in users. It shows how to tell the widget who is signed in, how to prove that identity with a signature from your server, which value to sign, and how to clear the identity on logout.
What identifying users gives you
Without identification, every visitor is anonymous until they type a name or email into the widget. When your site passes the signed-in user:
- the conversation in the inbox shows their name, email, phone and any custom attributes you send,
- the pre-chat form and the widget’s own name and email ask are skipped, because the details are already known,
- the widget starts a fresh conversation history when a different user signs in on the same browser.
When the identity is also verified with a user_hash:
- the inbox marks the visitor Identity verified by your site,
- the AI can use the visitor’s earlier conversations in this project as context,
- the Stripe and Your app integrations can answer for this visitor (unverified visitors are never looked up; Stripe also needs a proven email, see Sign the user id or the email),
- the AI can match the visitor’s problem against errors from your connected error trackers that affect them.
Everything a visitor sends without a valid user_hash is a claim. It is shown to your team, but integrations never look anything up by it.
Call identify()
Call Axoryn.identify() once the user is signed in:
window.Axoryn.identify({
user_id: '42',
email: 'jane@acme.com',
name: 'Jane Doe',
user_hash: '<computed on your server>',
phone: '+5511999999999',
custom: { plan: 'pro', company: 'Acme' },
})
| Field | Type | Notes |
|---|---|---|
user_id | string or number | Your app’s stable user id. Signed with user_hash when present. |
email | string | The user’s email address. |
name | string | Shown in the inbox and in the widget. |
phone | string | Optional. Shown in the inbox. |
custom | object | Optional extra attributes. Shown under Custom attributes in the inbox. New keys are merged into the ones already stored. |
user_hash | string | Hex HMAC-SHA256 signature computed on your server. See below. |
All fields are optional, but send at least one of name, email or user_id. Axoryn.setIdentity() is the same function under another name.
Some rules to know:
- A name or email already stored for this visitor is never overwritten by a later call.
- Calls made before the full widget has loaded are queued and sent when it loads.
- A failed or invalid
user_hashnever breaks the chat. The visitor stays unverified and can keep talking to you.
Set the identity before the script loads
If your pages are rendered on the server, you can set window.axorynIdentity before the widget script. The widget reads it when it starts:
<script>
window.axorynIdentity = {
user_id: '42',
email: 'jane@acme.com',
name: 'Jane Doe',
user_hash: '<computed on your server>',
}
</script>
<script src="https://api.axoryn.io/widget.js"
data-project-key="YOUR_WIDGET_KEY" async></script>
It takes the same fields as identify(). The widget trims the values and lowercases the email before sending them. In a single-page app where the user signs in without a page load, call identify() instead.
Verify identities with user_hash
The widget runs in the visitor’s browser, so anyone can call identify() with any user_id or email. Your server proves the identity by signing it with a secret key that only it knows.
Get the secret key
- Open the project and select Settings.
- Go to Identity verification and allowed sites (Security in the section list).
- Under Secret key, select Show key, then Copy.
Only owners and admins can see the key. Members see Only account admins can view the verification key.
Store the key in a server-side environment variable, for example AXORYN_IDENTITY_SECRET. Never put it in HTML or browser JavaScript: anyone holding it can sign any identity.
Compute the hash on your server
user_hash = hex( HMAC-SHA256( key = secret key, message = user_id ) )
When you do not send a user_id, sign the email instead. Use the secret key exactly as copied, as a text string. Do not hex-decode it.
Node.js:
import crypto from 'node:crypto'
// AXORYN_IDENTITY_SECRET lives in your server env, never in the browser.
const userHash = crypto
.createHmac('sha256', process.env.AXORYN_IDENTITY_SECRET)
.update(String(user.id)) // or user.email when you send no user_id
.digest('hex')
Ruby:
require "openssl"
# AXORYN_IDENTITY_SECRET lives in your server env, never in the browser.
user_hash = OpenSSL::HMAC.hexdigest(
"SHA256",
ENV.fetch("AXORYN_IDENTITY_SECRET"),
current_user.id.to_s # or current_user.email when you send no user_id
)
Python:
import hashlib, hmac, os
# AXORYN_IDENTITY_SECRET lives in your server env, never in the browser.
user_hash = hmac.new(
os.environ["AXORYN_IDENTITY_SECRET"].encode(),
str(user.id).encode(), # or user.email when you send no user_id
hashlib.sha256,
).hexdigest()
PHP:
<?php
// AXORYN_IDENTITY_SECRET lives in your server env, never in the browser.
$userHash = hash_hmac(
'sha256',
(string) $user->id, // or $user->email when you send no user_id
getenv('AXORYN_IDENTITY_SECRET')
);
Render the result into the page and pass it as user_hash. The value you sign must be the same user_id (or email) you pass to identify(). Axoryn checks the hash against that value with surrounding spaces removed, and against its lowercase form.
Tip: When you sign an email, sign it in lowercase. That always matches, including when you pass it through
window.axorynIdentity, which lowercases the email before sending it.
Rotate the key
The owner can select Generate new key. The current key stops working immediately: hashes signed with the old key no longer match, so new identifications fail verification until your server signs with the new key. Visitors who were already verified stay verified. Update your server’s environment variable right after rotating.
Sign the user id or the email
When identify() includes a user_id, Axoryn checks the hash against the user_id only. It checks the hash against the email only when no user_id is sent. That choice changes what your integrations receive:
Sign user_id | Sign email (no user_id sent) | |
|---|---|---|
| Visitor is verified | Yes | Yes |
Your user_id reaches Your app integration | Yes | No |
| The email counts as proven | No, unless proven another way | Yes |
| Stripe customer lookup by email | Only if the email is proven another way | Yes |
| Sentry finds this user’s errors by email | Only if the email is proven another way | Yes |
| Conversations under the same email on other devices are merged | Only if the email is proven another way | Yes |
A hash over the user_id does not vouch for the email sent next to it, so lookups that run by email only use a proven email. An email is also proven when the visitor opens a conversation link that Axoryn emailed to them.
When you sign the email, it must match the email already stored for that visitor, if any. If the visitor typed a different address earlier, for example in the pre-chat form, that visitor is not verified by the email hash.
Reset the identity on logout
When the user logs out of your app, call:
window.Axoryn.reset()
reset() forgets the visitor on this browser: the visitor credential, the current conversation, unread state and the last signed-in user. It then starts a fresh, anonymous widget with the same settings, so the next person on a shared computer does not see the previous user’s chat.
The widget also starts fresh on its own when identify() (or window.axorynIdentity) carries a different user_id than the last one on this browser. That check uses user_id only. If you sign emails and send no user_id, reset() is the only way to clear the previous user, so call it on every logout.
Visitors can also clear the identity themselves with Not you? inside the widget.