The js-client-sdk and the accompanying docs are open source and hosted on github.
Get started in a few quick steps.
- Create a free account on statsig.com
- Install the SDK
- Initialize the SDK
- Fetch Feature Gates or Dynamic Configs
You could skip this for now, but you will need an SDK Key and some Feature Gates or Dynamic Configs to use with the SDK in just a minute.
You can install the statsig SDK via npm, yarn or jsdelivr.
To access specific files/versions:
After installation, you will need to initialize the SDK using a Client SDK key from the "API Keys" tab on the Statsig console.
These Client SDK Keys are intended to be embedded in client side applications. If need be, you can invalidate or create new SDK Keys for other applications/SDK integrations.
Do NOT embed your Server Secret Key in client side applications
Now that your SDK is initialized, let's fetch a Feature Gate. Feature Gates can be used to create logic branches in code that can be rolled out to different users from the Statsig Console. Gates are always CLOSED or OFF (think
return false;) by default.
Feature Gates can be very useful for simple on/off switches, or more advanced user targeting. But what if you want to return an entirely different configuration to different users? What if you want to be able to send a different set of strings to your client for different locales? Or a different list of products for a new market (or new user)? Enter Dynamic Configs. The API is very similar to Feature Gates, but you get an entire json object you can configure on the server. For example:
You can then fetch typed Dynamic Config parameters and provide a default value as a fallback:
You should provide a user object whenever possible to your
initialize() call, passing as much information as possible in order to take advantage of advanced gate and config conditions (like country or OS/browser level checks). If the user is not known at SDK init time, you can still fetch values for logged out users until the user is known. At that point, update the gates and configs for the user using:
The User Object can be populated with a number of schematized attributes, or your own custom fields:
You can use the SDK to log events associated with the user. These events will be used to power A/B testing metrics in the future, and will show up in the Statsig console under the "Dashboard" tab (coming soon!)
For more information, see our SDK documentation on github.