Context
Environment metadata attached to events, and the sources they came from.
What is context
Context is a dictionary of metadata about an event and the environment it occurred in. It is captured automatically and stored on the event, so you can answer questions about the device, browser, and location of your traffic without instrumenting it yourself.
Server context
The server automatically adds only the following keys:
ip- the IP addresslocale- the localecountry- the country
Client context
The client web SDK adds environment details before sending an event:
browserandosdeviceTypeanddeviceModelscreenandviewporturl,path, andreferrertimezone
Custom context
Pass additional keys through the context option of track(). They are merged into the event's context alongside the automatic values:
import { Vanta } from '@vanta-dev/node'
const vanta = new Vanta({
apiKey: process.env.VANTA_API_KEY,
})
await vanta.track({
event: 'checkout.completed',
userId: 'user_123',
context: {
plan: 'pro',
feature: 'express-checkout',
},
})Sources
A source identifies where an event came from, such as web, node, or mobile. Sources are recorded on events and let you attribute analytics to the origin of the data, so you can compare behavior across your web app, backend services, and mobile clients.
Specifying a source
Set a default source in your client configuration:
import { Vanta } from '@vanta-dev/web'
const vanta = new Vanta({
apiKey: process.env.VANTA_API_KEY,
source: 'web',
})Or override the source for an individual event in track():
import { Vanta } from '@vanta-dev/node'
const vanta = new Vanta({
apiKey: process.env.VANTA_API_KEY,
})
await vanta.track({
event: 'order.created',
source: 'node',
data: {
orderId: 'ord_123',
},
})Sources are upserted as they are seen, so you do not need to create them ahead of time. Knowing which source produced an event is often the first thing you want when investigating a difference in behavior.