Back to Integrations

JavaScript SDK

Track events from your website

Installation

Method 1: CDN (Recommended)

Add this code snippet to your website before the closing </body> tag:

<!-- Add before closing </body> tag -->
<script src="https://cdn.alertstream.io/js/v1.js"></script>
<script>
  AlertStream.init('js_abc123def456ghi789');
</script>

Method 2: NPM Package

For modern JavaScript applications:

npm install @alertstream/sdk

Then in your code:

import AlertStream from '@alertstream/sdk';

AlertStream.init('js_abc123def456ghi789');

// Track custom events
AlertStream.track('form_submit', {
  name: 'John Doe',
  email: 'john@example.com',
  message: 'Hello!'
});

Auto-Track Forms

Automatically capture form submissions without writing custom code:

// Automatically track all form submissions
AlertStream.autoTrackForms({
  selector: 'form',
  eventType: 'form_submit'
});

// Track specific forms
AlertStream.autoTrackForms({
  selector: '#contact-form',
  eventType: 'contact_form_submit'
});

Track Custom Events

Send custom events with any data you want:

// E-commerce example
AlertStream.track('order_created', {
  order_id: '12345',
  amount: 299.99,
  customer_name: 'Jane Smith',
  items: 3
});

// User signup
AlertStream.track('user_signup', {
  email: 'user@example.com',
  plan: 'pro'
});

// Custom button click
document.getElementById('cta-button').addEventListener('click', () => {
  AlertStream.track('cta_clicked', {
    button_text: 'Get Started',
    page: window.location.pathname
  });
});

API Reference

AlertStream.init(apiKey, options)

Initialize the SDK with your API key. Call this once when your page loads.

AlertStream.track(eventType, data)

Send a custom event with optional data object.

AlertStream.autoTrackForms(options)

Automatically track form submissions. Options: selector, eventType.

AlertStream.identify(userId, traits)

Associate events with a specific user.

Download SDK

Want to self-host? Download the SDK files:

Next Steps

  1. Add the SDK to your website
  2. Create triggers to define when to send SMS alerts
  3. Test by triggering events on your site
  4. Monitor SMS delivery in your dashboard
Create Your First Trigger