Javascript SDK Getting Started
- If the JS SDK is installed using NPM, call
initializeDevCyclewith your client key, a user object, and an optional options object. - Otherwise, If you're using the CDN to install the JS SDK, call
DevCycle.initializeDevCyclewith your client key, a user object, and an optional options object.
The user object needs either a user_id, or isAnonymous set to true for an anonymous user. The options object is optional,
but can passed a logWriter for a custom logging solution and a logLevel, which must be one of info, debug, warn or error.
The default options are to set the logWriter to be the console and the logLevel to error.
const user = { user_id: 'my_user' }
const devcycleOptions = { logLevel: 'debug' }
// replace initializeDevCycle with DevCycle.initializeDevCycle if using the CDN
const devcycleClient = initializeDevCycle(
'<DEVCYCLE_CLIENT_SDK_KEY>',
user,
devcycleOptions,
)
Deferred Initialization
In many cases, user data is not available at the time of initialization. If the initialization call is made without a
user object, then by default the SDK will be instantiated with an "anonymous" user and a configuration will be
downloaded from DevCycle. The SDK makes a call to get the configuration for anonymous user and initializes.
If you would like to defer initialization of the SDK until your user data is available, you can pass the
deferInitialization option to the initializeDevCycle method. This will cause the SDK to not fetch a configuration until the
devcycleClient.identifyUser method is called with the user data.
Until that config is retrieved, all calls
to retrieve variable values will return their default values.
const devcycleOptions = { logLevel: 'debug', deferInitialization: true }
// replace initializeDevCycle with DevCycle.initializeDevCycle if using the CDN
const devcycleClient = initializeDevCycle(
'<DEVCYCLE_CLIENT_SDK_KEY>',
devcycleOptions,
)
DevCycleUser Object
DevCycleUser Typescript Schema
Initialization Options
The SDK exposes various initialization options which can be set on the initialization() method:
