Advice and answers from the UserGuiding Team
Users
Engagement
Settings
User
Learn how to utilize the UserGuiding's JavaScript API User methods

Identify

Sets the user ID and sends user attributes. When user identification is enabled, this method must be called first for UserGuiding SDK to work.


Type Definition

type identify = (
userId: string,
attributes?: Object
) => void


Example:

Identify user with user attributes


window.userGuiding.identify('1Ax69i57j0j69i60l4', {
 email: '[email protected]',
 name: 'Awesome User',
 created_at: 1644403436643,
})


Identify user with both user and company attributes


window.userGuiding.identify('1Ax69i57j0j69i60l4', {
 name: 'Awesome User',
 company: {
   id: '1', // *company id is required
   name: 'Awesome Company',
   created_at: 1644403436643,
 }
})


Identify user without attributes, only the user ID


window.userGuiding.identify('1Ax69i57j0j69i60l4')`


Track Event

Tracks a user action with an optional payload.


Type Definition

type track = (
event: string,
payload?: Object
) => void


Example:

Track event without metadata


userGuiding.track('subscription_started')


Track event with metadata


userGuiding.track('subscription_started', {
plan: 'enterprise',
created_at: 1644403436643
})



Clear Identity

Clears UserGuiding’s identity information for the current browser session.
This removes the authentication cookies used for User Identity Verification and resets the SDK’s user identity state (for example, to revoke Knowledge Base access on logout).


Type Definition

type clearIdentity = () => void


Example

Example logout flow


async function handleLogout() {
// 1. Invalidate your app session
await api.post('/logout')

// 2. Clear UserGuiding identity + KB access
window.userGuiding.clearIdentity()

// 3. Redirect or clean up app state
window.location.href = '/login'
}


Force Identify

Gets the latest attributes of the user. This is handy when you send attributes through a server-side integration and need the user's attribute updated within your application instantly.


Type Definition

type forceIdentify = () => void



Did this answer your question?
Related Articles