Skip to content

Users and events

Sets the current user’s ID and sends their attributes. If user identification is enabled for your project, call identify before anything else. Most other methods wait until identification completes.

type identify = (
userId: string | number,
attributes?: Record<string, unknown>,
) => void
userIdstring | numberrequired

Your own unique ID for the user. Use the same ID you send to the User API.

attributesobject

Key value pairs to store on the user. Attributes are merged into what UserGuiding already has, so you only need to send the ones that changed.

Show value rules
  • Values can be strings, numbers, booleans, dates or null.
  • Arrays are stored as list attributes. Each item is converted to a string, items longer than 1,024 characters are dropped, and only the first 100 items are kept.
  • Nested objects are ignored, except for the company key.
  • Include user_hash when identity verification is enabled.
attributes.companyobject

Creates or updates the user’s company and links the user to it.

Show properties
idstringrequired

Your own unique ID for the company. company_id also works.

namestring

Company name. company_name also works.

any other keystring | number | boolean

Stored as a custom company attribute.

window.userGuiding.identify('1Ax69i57j0j69i60l4', {
name: 'Jamie Rivera',
created_at: 1644403436643,
})

To update attributes for the user who is already identified, pass the attributes object as the only argument:

window.userGuiding.identify({ plan: 'enterprise' })

Records a custom event for the current user, with optional metadata.

type track = (event: string, metadata?: Record<string, unknown>) => void
eventstringrequired

Event name. Use a stable, lowercase name such as subscription_started.

metadataobject

Extra properties stored with the event.

window.userGuiding.track('subscription_started')

Fetches the latest attributes for the current user from UserGuiding. Call it after you update attributes on the server, through the User API or an integration, so the change takes effect in the open session right away.

type forceIdentify = () => void
await fetch('/api/upgrade-plan', { method: 'POST' })
window.userGuiding.forceIdentify()

Clears the current user’s identity from the browser. It removes the UserGuiding identity cookies, including the identity verification hash, and resets the SDK’s user state. Call it when a user signs out, for example to revoke their access to a private Knowledge Base.

type clearIdentity = () => void
async function handleLogout() {
// 1. Invalidate your app session
await api.post('/logout')
// 2. Clear the UserGuiding identity
window.userGuiding.clearIdentity()
// 3. Redirect
window.location.href = '/login'
}