identify() so their chats are linked to their customer profile in Sagepilot and their conversation history follows them across devices.
Identify a signed-in customer
Callidentify() after the widget is ready and your site knows who the customer is.
Other top-level fields are ignored. Put any extra data inside
custom_properties.
Sagepilot looks up the customer by user_id. If none exists, it looks for a customer with the same email. If neither exists, it creates a new customer.
Result
identify() resolves to an object. It does not throw.
When to call it
- Call it after sign-in, or on page load when a signed-in customer arrives.
- The identity is saved in the browser and restored on later page loads, so you do not need to call it on every page. Calling it again with the same customer is safe.
- If a different customer signs in on the same browser, call
logout()first and thenidentify()with the new customer.
Identity verification
Without verification, Sagepilot cannot confirm that a visitor is the customer they claim to be. Turn on identity verification for any site where customers sign in. When verification is on, everyidentify() call must include a user_hash: an HMAC-SHA256 signature of the user_id, created with a secret that only your server knows. Calls without a valid hash fail.
1
Turn on verification
In Sagepilot, open Channels, click your website widget, and open Identity. Turn on Enable Identity Verification and save the channel.
2
Store the secret on your server
Copy Your Secret Key and store it with your other server-side secrets, for example as an environment variable.
3
Generate the hash on your server
Sign the exact
user_id string you will pass to identify(), and output the result as lowercase hexadecimal.4
Pass the hash to the page
Render the hash into the page or return it from an authenticated endpoint, then pass it to
identify() as user_hash.Log out
When the customer signs out of your site, clear their identity from the widget:logout(), the chat resets to an anonymous session in this browser, and the customer’s conversations are no longer shown.
Read the identity state
getIdentityState() returns the current state synchronously:
Run code after identification
onIdentify(callback) runs your callback once the visitor is identified:
- If the visitor is already identified, the callback runs immediately.
- If an
identify()call is in progress, the callback runs when it succeeds. - If neither is true, the callback is not registered. Call
onIdentify()after you callidentify().
Identity and messages
Callingidentify() or logout() cancels any setDraft() or sendMessage() call that has not finished yet. Those calls resolve with the code identity_changed. Calls made while identify() is in progress return identity_pending. Wait for identify() to finish before you send a message on the customer’s behalf. See Draft and send messages.