Skip to main content

Javascript SDK Getting Started

Npm package version GitHub

  • If the JS SDK is installed using NPM, call initializeDevCycle with 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.initializeDevCycle with 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 dvcOptions = { logLevel: "debug" };
// replace initializeDevCycle with DevCycle.initializeDevCycle if using the CDN
const devcycleClient = initializeDevCycle("<DEVCYCLE_CLIENT_SDK_KEY>", user, dvcOptions);

DevCycleUser Object

DevCycleUser Typescript Schema

isAnonymousBooleanBoolean to indicate if the user is anonymous
user_idStringUnique user ID
emailStringUser's email
nameStringUser's name
languageStringUser's language
countryStringUser's country
appVersionStringApp version
appBuildNumberApp build
customDataDVCJSONKey/value map of properties to be used for targeting
privateCustomDataDVCJSONKey/value map of properties to be used for targeting. Private properties will not be included in event logging.

Initialization Options

The SDK exposes various initialization options which can be set on the initialization() method:

DevCycleOptions Typescript Schema

DevCycle OptionTypeDescription
enableEdgeDBBooleanEnables the usage of EdgeDB for DevCycle that syncs User Data to DevCycle.
loggerDVCLoggerLogger override to replace default logger
logLevelDVCDefaultLogLevelSet log level of the default logger. Options are: debug, info, warn, error. Defaults to info.
eventFlushIntervalMSNumberControls the interval between flushing events to the DevCycle servers in milliseconds, defaults to 10 seconds.
flushEventQueueSizeNumberControls the maximum size the event queue can grow to until a flush is forced. Defaults to 100.
maxEventQueueSizeNumberControls the maximum size the event queue can grow to until events are dropped. Defaults to 1000.
apiProxyURLStringAllows the SDK to communicate with a proxy of DevCycle bucketing API / client SDK API.
configCacheTTLNumberThe maximum allowed age of a cached config in milliseconds, defaults to 7 days
disableConfigCacheBooleanDisable the use of cached configs
disableRealtimeUpdatesBooleanDisable Realtime Updates
disableAutomaticEventLoggingBooleanDisables logging of sdk generated events (e.g. variableEvaluated, variableDefaulted) to DevCycle.
disableCustomEventLoggingBooleanDisables logging of custom events, from track() method, and user data to DevCycle.