Skip to main content
The browser SDK uses a positional argument style. Most methods return a Promise<Context>.

User identification

// Identify with user ID only
analytics.identify('user@example.com')

// Identify with traits
analytics.identify('user@example.com', {
  first_name: 'John',
  last_name: 'Doe',
  email: 'user@example.com',
  plan: 'premium',
  created_at: new Date().toISOString()
})

// With options and callback
analytics.identify(
  'user@example.com',
  { email: 'user@example.com' },
  {},
  () => {
    console.log('User identified successfully')
  }
)

Event tracking

analytics.track('button_clicked')

analytics.track('purchase_completed', {
  product_id: '123',
  product_name: 'Widget',
  price: 29.99,
  currency: 'USD',
  quantity: 1
})

analytics.track('signup_completed', { method: 'email' }, {}, () => {
  console.log('Event tracked successfully')
})

Page tracking

analytics.page()

analytics.page('Home')

analytics.page('Docs', 'Getting Started')

analytics.page('Product Detail', {
  product_id: '123',
  category: 'Electronics',
  url: window.location.href,
  referrer: document.referrer
})
For SPAs, call analytics.page() on route changes:
window.addEventListener('popstate', () => {
  analytics.page()
})

Screen tracking

analytics.screen('Dashboard', {
  user_type: 'premium'
})

Group tracking

analytics.group('company-123', {
  name: 'Acme Inc',
  plan: 'enterprise',
  employees: 100
})

Alias

Merge two user identities:
analytics.alias('user@example.com', 'anon-123')

Reset / logout

Clear persisted user and group identity:
analytics.reset()

function handleLogout() {
  analytics.reset()
  // ... rest of logout logic
}