Statsig Edge Config Adapter for Node.js

0.8.1 · active · verified Sun Apr 19

This package, `statsig-node-vercel`, provides a first-party integration between the Statsig server-side Node.js SDK and Vercel's Edge Config. It allows developers to store and retrieve Statsig configuration, including feature gates, dynamic configs, and ID lists, directly from Vercel Edge Config, leveraging its low-latency, globally distributed data store. The current stable version is 0.8.1, and its release cadence appears to be tied to updates in the main Statsig Node.js SDK and Vercel's Edge Config features, with a focus on optimization and direct data parsing. Key differentiators include seamless integration with Vercel infrastructure, reduced network latency for Statsig evaluations by utilizing Edge Config, and specific optimizations for ID list handling. It significantly streamlines the deployment and management of Statsig configurations within Vercel environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Statsig Node.js SDK using the Vercel Edge Config adapter, showing setup, environment variable usage, and a basic feature gate check.

import { EdgeConfigDataAdapter } from 'statsig-node-vercel';
import { createClient } from '@vercel/edge-config';
import statsig from 'statsig-node';

async function initializeStatsigWithVercel() {
  const edgeConfigClient = createClient(process.env.EDGE_CONFIG_CONNECTION_STRING ?? '');
  
  if (!process.env.EDGE_CONFIG_CONNECTION_STRING) {
    console.error('EDGE_CONFIG_CONNECTION_STRING is not set. Please configure your Vercel Edge Config.');
    return;
  }

  const dataAdapter = new EdgeConfigDataAdapter({
    edgeConfigClient: edgeConfigClient,
    edgeConfigItemKey: process.env.STATSIG_EDGE_CONFIG_ITEM_KEY ?? 'statsig-ITEM_KEY',
  });

  if (!process.env.STATSIG_SERVER_SECRET_KEY) {
    console.error('STATSIG_SERVER_SECRET_KEY is not set. Please provide your Statsig server secret key.');
    return;
  }

  await statsig.initialize(process.env.STATSIG_SERVER_SECRET_KEY, {
    dataAdapter: dataAdapter,
    // These options are recommended for optimal performance with Edge Config
    // to avoid blocking network calls for ID Lists on initialization.
    // Omit if you need ID list evaluation immediately on init.
    initStrategyForIDLists: 'none',
    disableIdListsSync: true
  });

  console.log('Statsig initialized successfully with Vercel Edge Config!');

  // Example: Check a feature gate
  const user = { userID: 'test-user-123' };
  const gateResult = await statsig.checkGate(user, 'a_feature_gate');
  console.log(`Feature gate 'a_feature_gate' for user ${user.userID}: ${gateResult}`);

  statsig.shutdown();
}

initializeStatsigWithVercel().catch(console.error);

view raw JSON →