Setup & Installation
Server-side feature flag evaluation
Last updated:
Installation
npm install @sessionsight/flagsInitialize
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
| Option | Type | Default | Description |
|---|---|---|---|
secretApiKey | string | required | Your secret API key |
propertyId | string | required | Your property ID |
environment | string | required | Environment name (e.g., production, staging) |
apiUrl | string | https://api.sessionsight.com | Override for self-hosted |
Usage
// 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:
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
FeatureFlagClientholds a single shared flag cache. If your flag values truly differ per visitor (e.g., percentage rollouts), callforRequest(req).refresh()before each read, or instantiate a per-requestFeatureFlagClient.
Cleanup
FeatureFlags.destroy();