On this page
Global properties & opt-out
Last updated
Register super properties merged into every event, mutate or drop events with before_send, and honor consent with opt-in/opt-out.
Attach properties to every event, transform events before they're sent, and respect user consent — all server-side.
#Global (super) properties
register() adds properties merged into every subsequent event at the lowest precedence (per-event properties win on a key collision). unregister() removes one.
vtilt.register({ app_version: '2.1.0', environment: 'production' })
vtilt.unregister('app_version')You can also set them once at construction:
const vtilt = new VTiltNode(token, {
globalProperties: { service: 'checkout-api' },
})#Person properties
Set properties on the person record without sending a custom event:
vtilt.setPersonProperties('user_123', { plan: 'pro' }) // $set on every event
vtilt.setPersonPropertiesOnce('user_123', { signup_source: 'docs' }) // $set_once#before_send
Pass a hook (or array of hooks) to mutate events or drop them. Return the event to keep it, or null to drop it. Multiple hooks run in order; the first null drops the event.
const vtilt = new VTiltNode(token, {
before_send: event => {
if (event.event === 'debug_event') return null // drop
event.payload.region = process.env.REGION
return event
},
})#Opt-out (GDPR)
vtilt.optOut() // drop all events until opted back in
vtilt.optIn()
vtilt.isOptedOut() // booleandisable() / enable() are a separate kill switch (e.g. to turn the SDK off entirely in a given environment).
#Lifecycle listeners
Subscribe to delivery events. on() returns an unsubscribe function.
const off = vtilt.on('error', err => logger.error('vtilt flush failed', err))
vtilt.on('flush', batch => metrics.increment('vtilt.events.sent', batch.length))| Event | Payload | Fires when |
|---|---|---|
capture | the event | an event is accepted (queued or sent) |
flush | the batch (array) | a batch is sent successfully |
error | an Error | a flush ultimately fails after retries |