Client-side Goal Tracking
Increment and decrement goals from the browser using the Insights SDK
Last updated:
Overview
The Insights SDK exposes a goals namespace for browser-side goal tracking. Because the Insights SDK is already initialized on the page, calls auto-attach the visitor and session context. No extra configuration is required.
Goal tracking through the browser is the supported replacement for split testing conversion tracking: any goals.increment() call is attributed to every split test the visitor is enrolled in.
Prerequisites
SessionSight.init() must have been called before you can fire goals. Calls made before init() return { success: false, error: 'SessionSight not initialized' }.
Increment a Goal
SessionSight.goals.increment('purchase', { amount: 5 });| Option | Type | Default | Description |
|---|---|---|---|
amount | number | 1 | For revenue goals, dollars booked (summed into progress). For count goals, ignored (each call = 1 conversion). Goal kind is set at creation in the dashboard. |
sessionId | string | auto | Override the session ID (uses the current one by default). Required in the no-session state if you want the call to reach the server — without it the SDK returns a silent no-op. |
metadata | Record<string, string> | - | Max 5 keys. Each key and value is capped at 256 characters. |
Decrement a Goal
SessionSight.goals.decrement('inventory');Takes the same options shape as increment, minus anything increment-specific.
Metadata
SessionSight.goals.increment('signup', {
metadata: { plan: 'pro', source: 'homepage' },
});Return Value
Both methods are synchronous and return a GoalResult:
{ success: boolean; error?: string }success: true means the browser enqueued the request through navigator.sendBeacon. Delivery is fire-and-forget, so there is no HTTP status to inspect.
Consent
Goals are session-scoped: every fire needs a session to attribute to. In the no-session state (before setConsent(true) or after setConsent(false)), goal calls are silent no-ops — nothing is sent, nothing is queued. When the user grants consent again, subsequent calls attribute to the new session. See Consent for the full lifecycle.
stopRecording() is orthogonal: it pauses rrweb visual capture without touching identity or consent. Goals continue to fire while the recorder is paused.
Server-side Alternative
If the conversion happens on your backend, use the Goals SDK with your secret API key. The server-side SDK requires sessionId on every call — thread it through from the originating user request (via forRequest(req)) or from metadata you persisted at the originating event (e.g. Stripe checkout metadata).