SDK Usage
There are two key ways to set up environments within your app:- Environment-specific SDK keys: These determine which rule sets are downloaded by the SDK based on the environment.
- Environment tier at SDK initialization: This defines how rules are evaluated for the app.
1. Environment-specific SDK Keys
Setting up environment-specific SDK keys allows you to control which rules are sent to the SDK. For instance, if an SDK is initialized with a key for the development environment, it will not receive rules set for staging or production environments. For more information, see Per-Environment API Keys below.2. Environment Tier Parameter
SDK keys can correspond to multiple environments. Therefore, it’s important to explicitly set the environment tier during SDK initialization to ensure the correct rules are applied. All SDKs accept anSDK Key
and an optional StatsigOptions
dictionary. The StatsigOptions
parameter includes the environment
key, which has a tier
field. This tier corresponds to one of your pre-configured environments (e.g., development, staging).
Note: If the environment tier is unset, all checks and event logs will default to “production.”Here’s an example of setting the environment tier in your code for the development environment:
Example (JS Client SDK):
Example (Node Server SDK):
Using Environments in Feature Gates
To configure environment-specific rules for a Feature Gate, follow these steps:-
Create a new Feature Gate: In the Statsig Console, create a new Feature Gate. For example, name it “development mode” to target only your development environment.
-
Specify Environments: When configuring the rule, check the Specify Environments box and select the environments you want to target. By default, rules are enabled for all environments unless specified otherwise.
-
Save your settings: After saving, the environment(s) for which the rule is enabled will be displayed below the rule name.
Configuring Environments
By default, Statsig provides three environments: Development, Staging, and Production. You can add more environments or rename the default ones, but the Production environment cannot be deleted or modified.Steps to Add or Edit Environments:
-
Navigate to Project Settings > Environments & Keys.
-
Click Edit to add new environments or reorder the existing ones using drag-and-drop.
Note: Reordering environments doesn’t affect any rule logic, but it helps convey the rollout hierarchy (e.g., development -> staging -> production) to your teams.
Per-Environment API Keys
To enhance security and privacy, Statsig allows you to create per-environment API keys. This ensures that SDKs initialized with specific environment keys will only access the rules relevant to that environment.Steps to Generate Environment-Specific API Keys:
- Go to Project Settings > Environments & Keys.
-
Click Generate New Key, and specify the environment for which you want to generate the API key.
Note: The default environments—Development, Staging, and Production—share the same server and client-side API keys. You can generate new keys for custom environments as needed.