Getting Started with Web SDK
Client SDK enables you to run experiments for user experience improvements in applications running on end-user devices. These applications include web and mobile apps.
Install
npm install @devunus/js-client-sdk
Initialize SDK - devunusClient.init
Obtain an environment key from the getting started | SDK keys. In addition to the environment key, you should also pass in a user context for feature targeting and user grouping, all of which are optional.
Each environment key is unique to each environment
import { devunusClient } from "@devunus/js-client-sdk";
const context: Context = {
user_id: 'your users id', // optional if added will allow flag targeting and generate user analytics
user_name: 'your users name', // optional, provides more meaningfully analytics
};
devunusClient.init(env_key, context);
Get Feature Flag
Feature flags can be used to create logic branches in your code that can be rolled out to users. By default will return false unless enabled in the admin console.
devunusClient.getFeatureStatus('new_invoice_feature')
Get Config
Config allows you to store values that can be used to drive logic in your application. By default will return the default value unless set in the admin console. Get config can use the same targeting rules as feature flags.
devunusClient.getConfig('flag_name','default value')
Get Notified when Feature Flag Changes
The SDK will automatically update when a feature flag or config is updated in the configuration screen, due to the global distribution of the flag configuration, updates can take up to 1 minute to be deployed.
If you need to get notified of these changes, you can use the on
method.
if (devunusClient.on('flags_update', () => {
if (devunusClient.getFeatureStatus('flag_name')) {
// do something
}
});
If you want to disable the automatic updates, you can set the live_config_updates
property to false. The value is true by default.
// disable live config updates
devunusClient.live_config_updates = false;