@vanta-dev/web
v0.1.2
Published
Browser SDK for Vanta event tracking with beacon transport and browser context
Maintainers
Readme
@vanta-dev/web
Browser SDK for the Vanta event tracking platform. Track events, identify users, record page views, and capture browser context from client-side code.
Installation
npm install @vanta-dev/webGetting started
import { Vanta } from '@vanta-dev/web'
const vanta = new Vanta({
apiKey: 'vk_your_api_key',
})
await vanta.track({ event: 'button_click', data: { section: 'hero' } })Configuration
const vanta = new Vanta({
apiKey: 'vk_...', // required
apiUrl: 'https://vantapi.pancake.wtf', // defaults to http://localhost:3001
source: 'website', // source identifier (default: 'website')
flushInterval: 10000, // ms between automatic flushes (default: 10000)
flushSize: 20, // queue size that triggers an immediate flush (default: 20)
})Tracking events
await vanta.track({
event: 'purchase',
userId: 'user_123',
data: { amount: 49.99, currency: 'USD' },
tags: { page: 'checkout' },
})Event names cannot start with $, which is reserved for internal Vanta events.
Identifying users
await vanta.identify({
userId: 'user_123',
email: '[email protected]',
name: 'Jane',
})
// Or set the user ID without sending an identify event
vanta.setUserId('user_123')
vanta.clearUserId()Page views
await vanta.page('Pricing')Sends a $page event with the current URL, path, search, hash, and document title.
Groups
await vanta.group({
groupId: 'org_456',
type: 'organization',
name: 'Acme Corp',
})Metrics
await vanta.measure({ name: 'render_time', value: 340 })
await vanta.increment('button_clicks')
await vanta.decrement('cart_items')Error tracking
try {
await riskyOperation()
} catch (err) {
await vanta.error(err)
}Browser context
Every event automatically includes browser context (URL, path, viewport, device type, browser, OS, timezone, locale). You can also read it directly:
import { getBrowserContext } from '@vanta-dev/web'
const context = getBrowserContext()Graceful shutdown
await vanta.shutdown()Flushes any remaining queued events.
Documentation
Read the full Web SDK documentation at vanta.pancake.wtf.
