@vizr/node
v0.1.0
Published
Vizr Node.js SDK — server-side event tracking for product analytics
Maintainers
Readme
@vizr/node
Node.js server-side SDK for Vizr product analytics.
Track events from your backend — subscription created, payment failed, API calls, etc.
Install
npm install @vizr/nodeQuick Start
import vizr from '@vizr/node';
// Initialize once at app startup
vizr.init({
siteId: 'vzr_your_site_id',
secretKey: 'vzr_live_your_api_key',
});
// Track server-side events
vizr.track('subscription_created', {
userId: 'user_123',
properties: { plan: 'pro', mrr: 99, trial: false },
});
// Identify a user
vizr.identify({
userId: 'user_123',
traits: { email: '[email protected]', name: 'Emma Wilson', plan: 'pro' },
});
// Flush before process exit
process.on('SIGTERM', async () => {
await vizr.shutdown();
process.exit(0);
});API
init(config)
| Option | Type | Default | Description |
|---|---|---|---|
| siteId | string | required | Your Vizr site ID |
| secretKey | string | — | API key (from Settings → API Keys) |
| host | string | https://vizr.app | Custom host |
| flushInterval | number | 5000 | Flush queue every N ms |
| batchSize | number | 50 | Flush when queue reaches N events |
| timeout | number | 10000 | Request timeout in ms |
| debug | boolean | false | Log to console |
track(eventName, options?)
Queue a server-side event.
identify(options)
Associate a user ID with traits.
flush()
Force-flush the event queue. Returns a Promise.
shutdown()
Flush and stop the flush timer. Call before process exit.
Framework Examples
Express middleware
app.use((req, res, next) => {
if (req.user) {
vizr.identify({ userId: req.user.id, traits: { email: req.user.email } });
}
next();
});Next.js API routes
export async function POST(req: Request) {
const session = await getSession();
vizr.track('api_called', { userId: session.userId, properties: { endpoint: '/api/export' } });
// ... rest of handler
}License
MIT — vizr.app
