Setup & Installation
Server-side goal tracking with the Goals SDK
Last updated:
Installation
npm install @sessionsight/goalsInitialize
import SessionSightGoals from '@sessionsight/goals';
SessionSightGoals.init({
secretApiKey: 'YOUR_SECRET_API_KEY',
propertyId: 'YOUR_PROPERTY_ID',
});The Goals SDK uses a secret API key and must run on your server, not in the browser.
Tracking goals from the browser? Use the Insights SDK instead. Once
SessionSight.init()has run on the page, callSessionSight.goals.increment('goal-id')orSessionSight.goals.decrement('goal-id'). The browser methods are synchronous (they usesendBeacon), auto-attach the visitor and session context, and authenticate with your public API key.
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
secretApiKey | string | required | Your secret API key from the dashboard |
propertyId | string | required | Your property ID |
apiUrl | string | https://api.sessionsight.com | Override for self-hosted or local dev |
Usage
// Count goal: each call counts as one conversion
await SessionSightGoals.increment('user-signups');
// Revenue goal (kind: 'revenue'): amount is dollars booked
await SessionSightGoals.increment('monthly-revenue', { amount: 49 });
// Decrement
await SessionSightGoals.decrement('active-users');Pairing with the Insights SDK
When the Insights SDK runs on your frontend, it writes an ss_sid cookie for the current recording session. Call forRequest(req) to auto-attach that sessionId to every goal call. Goals are session-scoped; visitor and user identity are resolved from the session on the backend.
app.post('/signup', async (req, res) => {
await SessionSightGoals.forRequest(req).increment('user-signups');
res.json({ ok: true });
});forRequest(req) works with every major framework (Next.js, SvelteKit, Nuxt, Hono, Express, Fastify, Koa, Workers, Remix, and more). See Pairing with backend SDKs for framework-specific examples and the full list of accepted request shapes.
Cleanup
Call destroy() when you’re done:
SessionSightGoals.destroy();