Docs

Setup & Installation

Server-side goal tracking with the Goals SDK

Last updated:

Installation

npm install @sessionsight/goals

Initialize

typescript
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, call SessionSight.goals.increment('goal-id') or SessionSight.goals.decrement('goal-id'). The browser methods are synchronous (they use sendBeacon), auto-attach the visitor and session context, and authenticate with your public API key.

Configuration

OptionTypeDefaultDescription
secretApiKeystringrequiredYour secret API key from the dashboard
propertyIdstringrequiredYour property ID
apiUrlstringhttps://api.sessionsight.comOverride for self-hosted or local dev

Usage

typescript
// 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.

typescript
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:

typescript
SessionSightGoals.destroy();