Your own unique ID for the user. Use the same ID you send to the User API.
Users and events
identify
Section titled “identify”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>,) => voiduserIdrequiredattributesKey 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
companykey. - Include
user_hashwhen identity verification is enabled.
attributes.companyCreates or updates the user’s company and links the user to it.
Show properties
idrequiredYour own unique ID for the company. company_id also works.
nameCompany name. company_name also works.
any other keyStored as a custom company attribute.
window.userGuiding.identify('1Ax69i57j0j69i60l4', { name: 'Jamie Rivera', created_at: 1644403436643,})window.userGuiding.identify('1Ax69i57j0j69i60l4', { name: 'Jamie Rivera', company: { id: '1', name: 'Acme Inc.', plan: 'enterprise', created_at: 1644403436643, },})window.userGuiding.identify('1Ax69i57j0j69i60l4')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>) => voideventrequiredEvent name. Use a stable, lowercase name such as subscription_started.
metadataExtra properties stored with the event.
window.userGuiding.track('subscription_started')window.userGuiding.track('subscription_started', { plan: 'enterprise', created_at: 1644403436643,})forceIdentify
Section titled “forceIdentify”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 = () => voidawait fetch('/api/upgrade-plan', { method: 'POST' })window.userGuiding.forceIdentify()clearIdentity
Section titled “clearIdentity”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 = () => voidasync 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'}