Identify a signed-in customer for browser events

Exchange your backend event key for a short-lived customer token, then boot event tracking in the browser.

As an owner, open Events → Set up tracking and generate or use the existing workspace event key. Store that key on your backend. If the customer already has a Bettercom profile, set its User ID to the stable ID your application will send.

On the server, derive the user from your authenticated session and request an event identity:

const response = await fetch(origin + '/events/identity', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer ' + eventKey,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ user_id: String(user.id), name: user.name })
});
if (response.status !== 201) throw new Error('Event identity failed');
const identity = await response.json();

Return the scoped token and expiry to your authenticated frontend. Boot with SupportDesk('boot', { event_token: identity.token }). If you use signed-in Messenger too, supply both tokens in that boot call. Refresh at the one-hour expiry and call SupportDesk('shutdown') on sign-out. Trigger one event and verify its contact in Events.

Related reading

Was this article helpful?