Skip to main content
The Node.js SDK uses an object-parameter API. Methods return void; use callbacks or emitter events for completion. Every event must include at least one of userId or anonymousId.

User identification

analytics.identify({
  userId: 'user@example.com',
  traits: {
    first_name: 'John',
    last_name: 'Doe',
    email: 'user@example.com',
    plan: 'premium'
  }
})

analytics.identify({
  userId: 'user@example.com',
  anonymousId: 'anon-123',
  traits: {
    email: 'user@example.com'
  }
})

analytics.identify(
  {
    userId: 'user@example.com',
    traits: { email: 'user@example.com' }
  },
  (err) => {
    if (err) {
      console.error('Identification failed:', err)
    }
  }
)

Event tracking

analytics.track({
  userId: 'user@example.com',
  event: 'purchase_completed',
  properties: {
    product_id: '123',
    product_name: 'Widget',
    price: 29.99,
    currency: 'USD'
  }
})

analytics.track({
  anonymousId: 'anon-123',
  event: 'page_viewed',
  properties: {
    page: 'homepage'
  }
})

analytics.track({
  userId: 'user@example.com',
  event: 'order_completed',
  properties: { order_id: 'ABC123' },
  timestamp: new Date()
})

Page tracking

analytics.page({
  userId: 'user@example.com',
  name: 'Home',
  properties: {
    title: 'Homepage',
    url: 'https://example.com'
  }
})

analytics.page({
  userId: 'user@example.com',
  category: 'Docs',
  name: 'Getting Started',
  properties: {
    url: 'https://example.com/docs/getting-started'
  }
})

Screen tracking

analytics.screen({
  userId: 'user@example.com',
  name: 'Dashboard',
  properties: {
    user_type: 'premium',
    version: '2.0'
  }
})

Group tracking

analytics.group({
  userId: 'user@example.com',
  groupId: 'company-123',
  traits: {
    name: 'Acme Inc',
    plan: 'enterprise',
    employees: 100,
    industry: 'technology'
  }
})

Alias

analytics.alias({
  userId: 'user@example.com',
  previousId: 'anon-123'
})
The Node.js SDK does not include reset(). Manage identity per request by passing userId / anonymousId on each call.