What It Does
Server-Side Tracking:- Track events from backend services
- Process webhook conversions
- Import historical data
- Track authenticated users
- Server-to-server attribution
- Secure API key authentication
- Event batching and retry logic
Installation
- Node.js 14+
- npm or yarn
Basic Usage
Initialize SDK
Track Events
Identify Users
Group Users
Page Tracking
Configuration Options
Initialization Config
Event Options
userId or anonymousId (or both for identity linking).
Advanced Features
Manual Flush
Close SDK
Get Anonymous ID
Event Batching
Events automatically batched for efficiency:TypeScript Support
Full TypeScript definitions included:Common Use Cases
Stripe Webhook
Background Job Processing
Shopify Webhook
Bulk Data Import
Serverless Function (AWS Lambda)
Identity Resolution
Link Anonymous to Known User:user_123 for complete attribution.
Get Anonymous ID from Web SDK:
Error Handling
retryLimit with exponential backoff.
Client Errors (4xx):
Not retried (invalid data, unauthorized).
Server Errors (5xx):
Retried automatically.
Best Practices
Initialize Once:Debugging
Enable Debug Mode:Rate Limits
API Limits:- 1,000 requests per second
- 10,000 events per batch
Troubleshooting
Events Not Appearing:- Verify API key from Settings → API Keys
- Check
debug: truefor error messages - Ensure
flush()called before app exits - Check Event Stream for events
- Verify workspace ID matches (if using)
- Pass both
userIdandanonymousIdin track() - Ensure
anonymousIdmatches Web SDK value - Check User Journeys for linked identities
- Reduce
maxQueueSize - Increase
flushAtfrequency - Call
flush()more often
API Reference
track(options)
Track an event.
Parameters:
userId(string, optional): User identifieranonymousId(string, optional): Anonymous identifierevent(string, required): Event nameproperties(object, optional): Event properties
Promise<void>
identify(userId, traits)
Identify a user.
Parameters:
userId(string, required): User identifiertraits(object, optional): User properties
Promise<void>
group(userId, groupId, traits)
Associate user with group.
Parameters:
userId(string, required): User identifiergroupId(string, required): Group identifiertraits(object, optional): Group properties
Promise<void>
page(userId, name, properties)
Track page view.
Parameters:
userId(string, required): User identifiername(string, optional): Page nameproperties(object, optional): Page properties
Promise<void>
flush()
Flush queued events immediately.
Returns: Promise<void>
close()
Flush events and cleanup.
Returns: Promise<void>
getAnonymousId()
Get SDK’s anonymous ID.
Returns: string