Skip to main content

Angular OpenFeature SDK - Getting Started

Npm package version GitHub

Installation

To install the Angular OpenFeature SDK into your application, you need to import the OpenFeatureModule as part of your root module. You will need to configure the DevCycleAngularProvider with your DevCycle Client SDK Key and any other options you need, and set the provider as part of the OpenFeatureModule.forRoot() method.

import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { OpenFeatureModule, OpenFeature } from '@openfeature/angular-sdk'
import DevCycleAngularProvider from '@devcycle/openfeature-angular-provider'

const devCycleProvider = new DevCycleAngularProvider(
environment.DEVCYCLE_CLIENT_SDK_KEY,
{ /* DevCycle Options */ }
);

// A `targetingKey` or `user_id` is required to initialize the DevCycle Provider.
OpenFeature.setContext({
targetingKey: "user123"
});

@NgModule({
imports: [
CommonModule,
OpenFeatureModule.forRoot({
provider: devCycleProvider,
}),
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}

info

It’s best to initialize DevCycle in your root module, so that it can be initialized as soon as the application is loaded.

Required TargetingKey

For DevCycle SDK to work we require either a targetingKey or user_id to be set on the OpenFeature context. This is used to identify the user as the user_id for a DevCycleUser in DevCycle.

Context properties to DevCycleUser

The provider will automatically translate known DevCycleUser properties from the OpenFeature context to the DevCycleUser object. DevCycleUser TypeScript Interface

For example all these properties will be set on the DevCycleUser:

openFeatureClient.setContext({
user_id: 'user_id',
email: '[email protected]',
name: 'name',
language: 'en',
country: 'CA',
appVersion: '1.0.11',
appBuild: 1000,
customData: { custom: 'data' },
privateCustomData: { private: 'data' },
})

Context properties that are not known DevCycleUser properties will be automatically added to the customData property of the DevCycleUser.

Context Limitations

DevCycle only supports flat JSON Object properties used in the Context. Non-flat properties will be ignored.

For example obj will be ignored:

openFeatureClient.setContext({
user_id: 'user_id',
obj: { key: 'value' },
})

DevCycle Options

The SDK exposes various initialization options which can be set by passing a DevCycleOptions object in the Provider constructor:

DevCycleOptions Typescript Schema

DevCycle OptionTypeDescription
enableEdgeDBBooleanEnables the usage of EdgeDB for DevCycle that syncs User Data to DevCycle.
loggerDevCycleLoggerLogger override to replace default logger
logLevelDevCycleDefaultLogLevelSet 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
deferInitializationBooleanDefer initialization (fetching configuration from DevCycle) until user is identified with identifyUser call
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.