Install & setup
Add @v-tilt/node for server-side tracking. Same event shape as the browser, with explicit identity per call.
Add @v-tilt/node for server-side tracking. The wire format is identical to the browser SDK (distinct_id, anonymous_id), so events from server and browser converge on the same person record automatically.
#Install
npm install @v-tilt/nodebash
#Initialise
Create a single client at process boot, reuse it everywhere, and call shutdown() before the process exits to flush any buffered events.
import { VTiltNode } from '@v-tilt/node'
const vtilt = new VTiltNode(process.env.VTILT_TRACKER_TOKEN!, {
host: process.env.VTILT_API_ENDPOINT || 'https://your-vtilt-instance.com',
})
vtilt.setContext({
distinctId: 'user_123',
anonymousId: req.cookies?.vt_anon,
})
vtilt.capture({
event: 'purchase',
properties: { amount: 99.99 },
})
vtilt.identify({
distinctId: 'user_123',
properties: { name: 'Alice', plan: 'pro' },
})
await vtilt.shutdown()typescript
#Recommended setup
- Construct one
VTiltNodeper process. The client batches events internally; multiple clients waste connections. - Read
VTILT_TRACKER_TOKENfrom environment variables, not hard-coded constants. The token is the same as the browser project token. - Always
await vtilt.shutdown()in your shutdown signal handler (SIGINT/SIGTERM/ Lambda terminate hook). Without it, the last batch of events may not flush. - For request-scoped frameworks (Express, Fastify, Next.js route handlers), prefer
setContext()per request over passingdistinctIdto every capture.