Janus Client SDK
A lightweight JavaScript library for tracking events from web applications. Automatically handles batching, retries, rate limiting, and persistence.
Lightweight (~3KB)Auto RetryBatchingPersistence
API Reference
Janus.init(apiKey, options)#
Initialize the SDK. Must be called before any tracking.
| Parameter | Type | Required | Description |
|---|---|---|---|
| apiKey | string | Yes | Your Janus API key (starts with jns_) |
| options.batchInterval | number | No | Flush interval in ms (default: 1000) |
| options.batchSize | number | No | Events to trigger immediate flush (default: 10) |
| options.debug | boolean | No | Enable debug logging (default: false) |
| options.persistQueue | boolean | No | Persist queue to localStorage (default: true) |
| options.trackPageViews | boolean | No | Auto-track page views on init (default: true) |
| options.trackSPANavigation | boolean | No | Auto-track SPA route changes (default: true) |
| options.onError | function | No | Callback for SDK errors: function(type, details) |
javascript
Janus.init('jns_your_api_key_here', {batchInterval: 2000, // Flush every 2 secondsbatchSize: 20, // Or when 20 events queueddebug: true // Enable console logging});
Janus.track(eventName, properties)#
Track a custom event.
| Parameter | Type | Required | Description |
|---|---|---|---|
| eventName | string | Yes | Name of the event |
| properties | object | No | Additional event properties |
javascript
Janus.track('purchase_completed', {orderId: 'ORD-123',amount: 99.99,currency: 'USD',items: ['item1', 'item2']});
Janus.page(pageName, properties)#
Track a page view. Called automatically on init and during SPA navigation by default. Use this for manual tracking or to pass custom page names/properties.
| Parameter | Type | Required | Description |
|---|---|---|---|
| pageName | string | No | Name of the page (defaults to document.title) |
| properties | object | No | Additional properties |
javascript
// Simple page viewJanus.page();// Named page view with propertiesJanus.page('Product Details', {productId: 'SKU-123',category: 'Electronics'});
Janus.identify(userId, traits)#
Identify a user. Links all future events to this user ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
| userId | string | Yes | Unique user identifier |
| traits | object | No | User traits/properties |
javascript
Janus.identify('user_12345', {email: 'user@example.com',name: 'John Doe',plan: 'pro',signupDate: '2024-01-15'});
Janus.reset()#
Reset user identity. Call this on logout to generate new anonymous IDs.
javascript
// On user logoutfunction logout() {Janus.reset();// ... rest of logout logic}
Janus.flush()#
Manually flush the event queue. Returns a Promise.
javascript
// Force send all queued eventsawait Janus.flush();
Janus.getConfig()#
Get current SDK configuration (useful for debugging).
javascript
console.log(Janus.getConfig());// {// batchInterval: 1000,// batchSize: 10,// apiKey: 'jns_abc123...',// distinctId: 'user_xyz',// sessionId: 'sess_abc',// queueLength: 3,// isInitialized: true// }
Need Help?
If you have questions or run into issues, check out our troubleshooting guide or reach out to our support team.
Troubleshooting Guide