Migrating to @statsig/js-client
Migrate soon! Official support for statsig-js ends Jan 31, 2025.
The architecture and majority of the APIs in the updated SDK have been retained; however, modifications have been made to address common pitfalls, resolve existing issues, and streamline the SDK logic, resulting in some breaking changes.
Breaking Changes
- The SDK now offers both a synchronous and asynchronous initialization and updateUser methods.
- The "getConfig" method has changed to "getDynamicConfig"
- When Bootstrapping, you'll now have to pass the hash parameter as 'djb2'
- The top-level static instance has moved to a static method, StatsigClient.instance()
- Overrides have moved into their own package: js-local-overrides
- Parameters for GDPR compliance have changed and been centralized
- The method to retrieve a stableID has changed
- The structure of cached values has changed, with implications on first-run experience
- Several StatsigOptions have changed
- Manual exposure logging methods have been deprecated (
getExperimentWithExposureLoggingDisabled
,checkGateWithExposureLoggingDisabled
). The checkGate and getExperiment methods now support a second argument to suppress exposure logging as shown here.
Initialization
Previously, the SDK employed a single method for initialization. However, we have recognized that waiting for a method call during app startup can be impractical. Consequently, we have introduced two distinct initialization approaches: one synchronous and one asynchronous.
Synchronous initialization will leverage cache (if available), returning immediately. Data for subsequent sessions will then be fetched in the background.
Asynchronous initialization, on the other hand, is awaitable and ensures that the most current data is fetched and used.
- statsig-js (Legacy)
- New
import Statsig from "statsig-js";
// initialize returns a promise which always resolves
await Statsig.initialize(
"client-sdk-key",
{ userID: "some_user_id" },
{ environment: { tier: "staging" } } // optional, pass options here if needed
);
You can read more about StatsigClient initialization here.