@jamesbond007db05/events-sdk
v1.0.1
Published
Multi-key analytics tracking SDK
Maintainers
Readme
Events SDK
A lightweight SDK for tracking events and user behavior in your application.
🚀 Installation
npm install @jamesbond007db05/events-sdk⚡ Setup
Initialize the SDK once when your app starts:
import { initTracker } from '@jamesbond007db05/events-sdk';
const tracker = initTracker({
apiKey: 'your_api_key_here',
autoPage: true
});⚙️ Configuration
Pass options directly to initTracker:
initTracker({
apiKey: 'your_api_key',
autoPage: true,
batchSize: 20,
flushIntervalMs: 5000
});Options
apiKey(required) – Your API keybatchSize– Number of events per batchflushIntervalMs– Flush interval in millisecondssampleRate– Control event samplingautoPage– Automatically track page viewsdebug– Enable debug loggingmaxRetries– Retry attempts for failed requestsrequestTimeoutMs– Network timeout durationmaxEventBytes– Max size of a single eventmaxBatchBytes– Max size of a batchstorageKey– Storage key for persistence
📊 Usage
Track an event
await tracker.track('button_clicked', {
label: 'signup'
});Identify a user
await tracker.identify('user_123', {
email: '[email protected]'
});Link anonymous user to logged-in user
await tracker.alias('anon_id', 'user_123');Track page view manually
await tracker.page({
title: 'Pricing'
});Track event with user
await tracker.trackWithUser('user_123', 'purchase_completed', {
amount: 199
});Send events immediately
await tracker.flush();🧠 Access existing tracker
import { getTracker } from '@jamesbond007db05/events-sdk';
const tracker = getTracker();🧪 Utilities
Validate API key
import { validateApiKeyFormat } from '@jamesbond007db05/events-sdk';Validate payload
import { validatePayload } from '@jamesbond007db05/events-sdk';Normalize errors
import { normalizeSdkError } from '@jamesbond007db05/events-sdk';🌐 Environment
- Modern browsers
- Node.js 18+
🚀 Release
npm version patch
git push origin --tags📄 License
MIT
