vTilt
By roleFoundersKnow what to fix firstMarketersSee what happens after the clickCMOsSee what your budget really buys
By businessSaaSTurn signups into active usersEcommerceSee why shoppers abandon cartsAgenciesProve your work to clientsEnterpriseOne customer record for every team
MeasureWeb AnalyticsFind where buyers leaveSession ReplaySee why they left, not just that they didAdsKnow what paid visitors do nextIntegrationsOne snippet feeds your stack
ThinkPeopleOne profile per customerCustomer MemoryvTilt remembers every visitorSite KnowledgeAnswers and audits from your own pages
ActAsk AIAnswers from real behaviorAI ChatChat that knows the visitorEmail CampaignsEmail from real visits
PricingWhy vTiltDocs
Docs / Context & shutdown
Getting Started
OverviewInstallInitializeIdentify usersTrack eventsLogout & resetVerify eventsCommon mistakes
Guides
Event forwardingReverse proxyRealtime dashboardSite knowledge
Frontend frameworks
Next.jsNuxt.jsVue.jsReactReact RouterRemixGatsbySvelte / SvelteKitAstroAngularTanStack StartDocusaurus
Backend frameworks
NestJSHonoCloudflare WorkersDjangoFlaskLaravelPhoenixRuby on Rails
Backend languages
PythonPHPRubyElixirGoJava.NET / C#Rust
Stack guides
Vue + PHP
API Reference
Browser SDK
Script bundlesAutocaptureWeb VitalsSession recordingChat widgetFeature readinessRemote configurationDebug logging
Node SDK
Install & setupCapture, identify & aliasContext & shutdownGlobal properties & opt-outError tracking
MCP server
Guides
OverviewAuthenticationOAuthAgent skills (prompts)AI intelligenceSite knowledgeGoogle AdsMeta Ads
Client setup
CursorClaude DesktopVS CodeCodex

Getting Started

OverviewInstallInitializeIdentify usersTrack eventsLogout & resetVerify eventsCommon mistakes

Guides

Event forwardingReverse proxyRealtime dashboardSite knowledge

API Reference

Install & setupCapture, identify & aliasContext & shutdownGlobal properties & opt-outError tracking

MCP server

On this page

On this page

  • setContext / clearContext
  • flush & shutdown
DocsAPI ReferenceNode SDKContext & shutdown

Context & shutdown

Last updated July 22, 2026

Set per-request identity once with setContext() so capture() calls stay clean. Always shutdown() before the process exits.

Set per-request identity with setContext() so you don't repeat distinctId/anonymousId on every capture(). Always call shutdown() before process exit to flush queued events.

#setContext / clearContext

Set distinctId and optional anonymousId from session or cookie at the start of a request; clear at the end. You can also set the end-user ip (and optionally userAgent / referrer) here so every capture() in the request is geolocated like a browser event — see Geolocation & end-user metadata.

vtilt.setContext({
  distinctId: req.user?.id,
  anonymousId: req.cookies?.vt_anon,
  ip: req.ip, // enables GeoIP for events in this request
})
vtilt.capture({ event: 'page_view', properties: { path: req.path } })
vtilt.clearContext()
typescript

Note

A server-side SDK cannot detect the visitor's browser, so events captured from the server never include $browser / $os / device properties. Forward ip to get geolocation; pass userAgent / referrer only when your server actually knows them (e.g. an API gateway forwarding the original request).

In Express / Fastify, wrap this in middleware so every handler downstream inherits the identity. In Next.js route handlers, set context at the top of the handler, run your logic, and call clearContext() in a finally block.

#flush & shutdown

flush() sends the queue immediately. shutdown() flushes and stops the timer (use before process exit).

await vtilt.flush() // optional: send now
await vtilt.shutdown(30_000) // flush + stop, 30s timeout
typescript
MethodWhen to callNotes
flush()Right before a known boundary (e.g. webhook response, lambda return) where queued events would otherwise be lost.Idempotent. Safe to call multiple times.
shutdown(timeoutMs)Process termination — SIGINT, SIGTERM, lambda extension shutdown, container stop.Stops the internal flush timer. Subsequent calls are no-ops.

Important

Forgetting shutdown() in serverless / edge runtimes is the #1 reason events go missing. The default flush interval is generous; without shutdown, the last interval's worth of events disappear with the runtime.

PreviousCapture, identify & aliasNode SDKNextGlobal properties & opt-outNode SDK