Core / Node.js SDK
Use @flash-analytics/sdk for Node.js services, backend jobs, and custom JavaScript integrations.
The Core SDK is the shared base SDK used by the browser wrappers and by custom Node or JavaScript integrations.
Install
npm install @flash-analytics/sdk@2.2.0pnpm add @flash-analytics/sdk@2.2.0Initialize
import { FlashAnalytics } from '@flash-analytics/sdk';
const analytics = new FlashAnalytics({
appId: process.env.FLASH_ANALYTICS_CLIENT_ID!,
secretKey: process.env.FLASH_ANALYTICS_SECRET_KEY!,
endpoint: 'https://api.flashanalytics.app',
platform: 'node',
appVersion: '1.2.3',
buildNumber: '120',
captureVariants: true,
});Core APIs
await analytics.identify({
profileId: 'user-123',
email: 'user@example.com',
});
await analytics.track('job_completed', { queue: 'imports' });
analytics.setGlobalProperties({ plan: 'pro' });
const session = analytics.getSession();Experiments
Enable captureVariants to keep a local cache of assignments in sync automatically. On each new session all experiments are fetched; after identify() only profile-mode assignments are refreshed; on session expiry only session-mode entries are removed.
// All cached assignments — no API call
const all = analytics.getAllExperiments();
// Single experiment — checks cache first, falls back to API if not found
const assignment = await analytics.getExperimentById('checkout-cta');
console.log(assignment?.variantName);
// Manual assignment (always calls the API)
const assignments = await analytics.autoAssignExperiments();
const variant = await analytics.assignExperiment('checkout-cta');Remote config
const config = await analytics.fetchRemoteConfig({
country: 'IN',
});
const featureFlag = config.getBoolean('feature_flag', false);
const welcomeText = config.getString('welcome_text', 'Welcome');
const maxItems = config.getNumber('max_items', 10);
const theme = config.getJson('theme_config', {});Remote config automatically includes platform, app version, build number, identified profile ID, primitive global properties, language, country, and a random seed where available.