Install the JavaScript SDK v6+
The steps necessary to install the Optimizely Feature Experimentation JavaScript SDK into your application.
Warning
This content covers the Feature Experimentation JavaScript SDK v6 features currently in pre-production testing and is subject to change before release.
The JavaScript SDK can be used in Node, browser, React Native, and other platforms (using the universal bundle) and is distributed through npm.
Minimum SDK version
v6.0.0+
For versions 5.3.5 and below, see JavaScript (Browser) SDK or JavaScript (Node) SDK.
See the SDK compatibility matrix documentation for a list of current SDK releases and the features they support.
Install
Using npm
.
npm install --save @optimizely/optimizely-sdk
Using yarn
.
yarn add @optimizely/optimizely-sdk
Using pnpm
.
pnpm add @optimizely/optimizely-sdk
Using deno
(no installation required).
import optimizely from "npm:@optimizely/optimizely-sdk"
Installation on React Native
For the React Native platform, additional configuration is required. After installing the JavaScript SDK, you need to install the following peer dependencies in your React Native application to enable features like datafile caching and offline event persistence.
npm install --save \
@react-native-async-storage/async-storage \
@react-native-community/netinfo \
react-native-get-random-values \
fast-text-encoding
@react-native-async-storage/async-storage
– Used to enable datafile caching by storing the datafile locally on the user's device. It also enables offline event persistence by temporarily storing events while the device is offline. However, using this package is optional, you can provide your own custom cache implementation instead.@react-native-community/netinfo
– Required to detect changes in internet connectivity. Ensures that any events triggered while offline are retried once connectivity is restored.react-native-get-random-values
– Required to support thecrypto.getRandomValues()
API.fast-text-encoding
– Required to support encoding functionality used in user bucketing.
If you prefer to use a different persistent caching solution instead of @react-native-async-storage/async-storage
, you can pass your own implementation that conforms to the Store<string>
interface in the following cases:
- Polling config manager – If you are using the polling project config manager, provide your custom
cache
implementation in the config. - Batch event processor – If you are using the batch event processor, provide your custom
eventStore
in the config.
By doing this, you can avoid installing @react-native-async-storage/async-storage
and instead use your own implementation to handle caching and event storage.
The full JavaScript SDK source code is available on GitHub.
Next
After installing, you must initialize the SDK.
Updated 1 day ago