Use the Jolt Node.js SDK to track trusted events such as completed payments, subscriptions, processed jobs, and invitations. The SDK requires Node.js 18 or newer.
Write keys are secrets. Never include them in browser code or commit them to your repository.
npm install @jolt-analytics/nodeimport { Jolt } from '@jolt-analytics/node'
const jolt = new Jolt({
writeKey: process.env.JOLT_WRITE_KEY
})
await jolt.track('subscription_started', {
userId: user.id,
properties: { plan: 'pro' },
context: {
path: '/checkout',
appVersion: '1.4.0'
}
})The SDK sends events to Jolt immediately and rejects the returned promise when the API does not accept a request. Configure a custom endpoint in the constructor when using a self-hosted API.
Use trackBatch() to send between 1 and 100 events in a single request.
await jolt.trackBatch([
{
event: 'invoice_paid',
userId: user.id,
properties: { amount: 49 }
},
{
event: 'subscription_started',
userId: user.id,
properties: { plan: 'pro' }
}
])event: Lowercase event name up to 64 characters, such as subscription_started.userId: Stable string or numeric user identifier, up to 255 characters.properties: Custom JSON object, limited to 16 KiB and three nesting levels.timestamp: Optional ISO date, up to seven days old or five minutes in the future.context: Optional sessionId, path, referrer, ip, userAgent, and appVersion values.Call jolt.identify(user.id) in the browser and send the same value as userId from your backend. Jolt will then treat both sources as the same user in Users and Flows.
Environments that cannot use the Node.js SDK can send the same payload directly to the events endpoint.
await fetch('https://usejolt.io/api/v1/events', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.JOLT_WRITE_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
batch_id: crypto.randomUUID(),
events: [{
event: 'subscription_started',
user_id: user.id,
properties: { plan: 'pro' }
}]
})
})