JavaScript SDK

Full programmatic control with the EventDash JavaScript SDK

Initialization
The tracker automatically initializes when the script loads. You can also access it via the global window.eventDash object.
// The tracker is available globally after script loads
if (typeof window !== 'undefined' && window.eventDash) {
  // Tracker is ready to use
  console.log('EventDash initialized')
}
Track Custom Events
Track any custom event with optional properties

Basic Event Tracking

// Track a simple event
window.eventDash.track('button_clicked', {
  buttonId: 'signup-btn',
  page: 'homepage',
  userType: 'free'
})

E-commerce Events

// Track a purchase
window.eventDash.track('purchase', {
  orderId: '12345',
  amount: 99.99,
  currency: 'USD',
  items: [
    { id: 'prod-1', name: 'Product 1', price: 49.99 },
    { id: 'prod-2', name: 'Product 2', price: 49.99 }
  ]
})

Form Submission

// Track form submission
document.getElementById('contact-form').addEventListener('submit', (e) => {
  window.eventDash.track('form_submit', {
    formName: 'contact_form',
    fields: ['name', 'email', 'message']
  })
})
Page View Tracking
Page views are tracked automatically on load and navigation. Use manual tracking only for virtual pages.
// Optional: track a virtual page
window.eventDash.trackPageView('/custom-page', 'Custom Page Title')
User Identification
Identify users and associate traits (optional, for authenticated users)
// Identify a user
window.eventDash.identify('user-123', {
  email: 'user@example.com',
  plan: 'premium',
  name: 'John Doe'
})
Error Tracking
Manually track errors with context
// Track a custom error
try {
  // Some code that might fail
} catch (error) {
  window.eventDash.trackError(error, {
    context: 'payment_processing',
    userId: 'user-123'
  })
}
Flush Events
Manually flush pending events (useful before page navigation)
// Flush all pending events
await window.eventDash.flush()
Available Methods
track(eventName, properties?)

Track a custom event with optional properties

trackPageView(url?, title?)

Optional: track a virtual page view (auto-tracked by default)

identify(userId, traits?)

Identify a user and associate traits

trackError(error, context?)

Manually track an error with optional context

flush()

Flush all pending events immediately