Tell the widget who the user is. A signed userToken verifies that identity, so their conversations link to them securely.
User
Pass the current user to identify them. The contact form then hides its email field.
Productlane.init({
widgetKey: "<your-widget-key />",
user: {
email: "[email protected]",
},
})Email is the only identifier the user object accepts, and it has no field for your own user ID. To identify a visitor by your own ID, sign a userToken with externalId instead of email, as described under Authentication. A signed userToken needs the user's email or an externalId. You can add an optional name to user. To group users by account, use orgExternalId in a signed token, as described under Multi-tenant apps.
Authentication
Pass a signed JWT to verify who the user is, so their conversations link to them securely.
With identity verification on and a private portal, the widget refuses a message sent with only a user email and shows "authentication required". Pass a signed userToken as described below, or turn identity verification off in Settings → Widget.
1. Generate a signing secret
Click Generate Signing Secret on the widget settings page. The secret starts with wg_sec_.
2. Sign a token on your backend
Sign with HS256, and include the user's email, an issued-at time (iat), and an expiry (exp). The expiry can be at most 1 hour after iat. It does not limit how long the user stays signed in: the widget exchanges the token for a session that lasts 12 hours.
const jwt = require("jsonwebtoken")
const secret = "wg_sec_..."
const payload = {
email: user.email,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 15 * 60, // 15 minutes (recommended)
}
const userToken = jwt.sign(payload, secret, { algorithm: "HS256" })3. Pass the token to the widget
Pass it as userToken when you initialize, or set it later, for example after login:
Productlane.init({
widgetKey: "<your-widget-key />",
userToken: "<user-token>",
})
Productlane.set({ userToken: "<user-token>" })Identify a user without an email
For visitors who stay anonymous, sign the token with your own user ID in externalId and leave out email.
const payload = {
externalId: user.id,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 15 * 60,
}
const userToken = jwt.sign(payload, secret, { algorithm: "HS256" })The token needs an
emailor anexternalId. When it has both, Productlane uses the email.externalIdhas 1 to 256 characters. Productlane accepts it only from a token signed with your workspace's signing secret.Each ID gets its own contact. IDs that differ by case or punctuation, like
User_42anduser_42, are different contacts.The contact is named after the ID unless you add a
nameto the token. Live chat threads are titled "Live Chat with" followed by that name.Productlane stores the contact under a generated placeholder address that does not contain the ID. It does not send email to these contacts, so replies show up in the widget.
When the ID in the token changes, the widget verifies the new visitor and starts a new session.
Sign out
Productlane.signOut()Multi-tenant apps
When one person can switch between several customer accounts in your app, give each account its own widget history. Add the account to the token you sign.
orgExternalId: your id for the account (the tenant).orgName: the account's name, shown on the company in Productlane.
const payload = {
email: user.email,
orgExternalId: tenant.id,
orgName: tenant.name,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 15 * 60,
}
const userToken = jwt.sign(payload, secret, { algorithm: "HS256" })Pass a new token after login and every time the user switches account:
Productlane.set({ userToken })The widget then starts a fresh chat for that account. The request list shows that account's requests only, even when the same person belongs to several accounts. Each account appears as a company in Productlane, created the first time a token names it. Productlane fills the new company's External IDs field with the orgExternalId automatically. If a company in your workspace already lists that id, Productlane uses that company and creates no new one.
Productlane reads
orgExternalIdandorgNameonly from tokens signed with your workspace's own signing secret.
On an account switch, call Productlane.set({ userToken }) alone. Calling signOut() at the same time can clear the new session.
Without identity verification
Anonymous visitors keep their chats in the browser, shared by every account on your domain. Call Productlane.signOut() when the user switches account to clear them.
Use userToken or user, not both
Setting the plain user object after a userToken, for example Productlane.set({ user: { email: ... } }), overwrites the verified session and signs the user out. Use userToken for signed-in users and user for simple identification.
Automatic portal sign-in
A user signed in to the widget with a userToken is also signed in to your portal when they click a link that opens it, such as a roadmap item, a changelog entry, a docs article, or their requests.
The widget asks for a short-lived, one-time code when the user clicks a portal link.
The portal exchanges the code for a session.
Turn on Portal Authentication on the widget settings page. It appears once you have generated a signing secret.
With Multiple Portals, the session opens the Main portal alone unless the token lists other portals in portalScopes. See SSO.
