Docs

Setup & Installation

Server-side feature flag evaluation

Last updated:

Installation

npm install @sessionsight/flags

Initialize

typescript
import FeatureFlags from '@sessionsight/flags';

await FeatureFlags.init({
  secretApiKey: 'YOUR_SECRET_API_KEY',
  propertyId: 'YOUR_PROPERTY_ID',
  environment: 'production',
}, { userId: 'user-123' });

The Flags SDK uses a secret API key and must run on your server, not in the browser.

Configuration

OptionTypeDefaultDescription
secretApiKeystringrequiredYour secret API key
propertyIdstringrequiredYour property ID
environmentstringrequiredEnvironment name (e.g., production, staging)
apiUrlstringhttps://api.sessionsight.comOverride for self-hosted

Usage

typescript
// Boolean flag
const showBeta = FeatureFlags.getBooleanFlag('beta-ui', false);

// String flag
const bannerText = FeatureFlags.getStringFlag('banner-message', 'Welcome!');

// Per-request evaluation with visitor context
await FeatureFlags.refresh({
  visitorId: 'visitor-uuid',
  userId: 'user-123',
  plan: 'enterprise',
});
const hasAccess = FeatureFlags.getBooleanFlag('advanced-analytics', false);

Pairing with the Insights SDK

If Insights is installed on your frontend, the ss_vid cookie identifies the visitor (enabling segment_match targeting) and ss_sid identifies their current recording session. forRequest(req) auto-merges both into every init() / refresh() call:

typescript
app.use(async (req, res, next) => {
  const flags = FeatureFlags.forRequest(req);
  await flags.refresh({ userId: req.user?.id });
  res.locals.flags = flags;
  next();
});

// Later in a handler:
const hasAccess = res.locals.flags.getBooleanFlag('advanced-analytics', false);

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.

The underlying FeatureFlagClient holds a single shared flag cache. If your flag values truly differ per visitor (e.g., percentage rollouts), call forRequest(req).refresh() before each read, or instantiate a per-request FeatureFlagClient.

Cleanup

typescript
FeatureFlags.destroy();