Skip to content

JavaScript SDK

Programmatic control after the tracker script loads — goals, custom events, and identify.

Initialization
The tracker automatically initializes when the script loads. You can also access it via the global window.eventDash object.
javascript
// The tracker is available globally after script loads
if (typeof window !== 'undefined' && window.eventDash) {
  // Tracker is ready to use
  console.log('EventDash initialized')
}
Queued Goal Tracking (Recommended)
Add this snippet in your HTML head to queue goals before the tracker loads.
html
<script>
  window.eventdash = window.eventdash || function() {
    window.eventdash.q = window.eventdash.q || [];
    window.eventdash.q.push(arguments);
  };
</script>
Track Goals
Send goal events for conversions and funnel steps

Immediate (SDK)

javascript
window.eventDash.trackGoal('signup', {
  plan: 'pro',
  source: 'pricing_page'
})

Queued (before SDK loads)

javascript
window.eventdash('signup', {
  plan: 'pro',
  source: 'pricing_page'
})
Track Custom Events
Track any custom event with optional properties

Basic Event Tracking

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

Ecommerce (use goals)

javascript
// Fire on the thank-you page after payment succeeds
window.eventDash.trackGoal('purchase', {
  order_id: '12345',
  amount: 99.99,
  currency: 'USD'
})

Store events belong on ecommerce goals, not track().

Form Submission

javascript
// 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.
javascript
// Optional: track a virtual page
window.eventDash.trackPageView('/custom-page', 'Custom Page Title')
User Identification
Identify users and associate traits (optional, for authenticated users)
javascript
// Identify a user with non-PII traits
window.eventDash.identify('user-123', {
  plan: 'pro',
  accountType: 'team'
})
Error Tracking
Manually track errors with context
javascript
// 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)
javascript
// Flush all pending events
await window.eventDash.flush()
Available Methods
trackGoal(goalName, params?)

Track a goal event for conversions and funnels

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