Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

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 (Browser) SDK v6 features currently in pre-production testing and is subject to change before release

For the latest released version, see JavaScript (Browser) SDK.

The JavaScript (Browser) 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+

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 setup is required. After installing the JavaScript SDK, you’ll 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 is 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 is required to detect changes in internet connectivity. It ensures that any events triggered while offline are retried once connectivity is restored.
  • react-native-get-random-values is required to support the crypto.getRandomValues() API.
  • fast-text-encoding is 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 interface in the following cases:

  1. Polling Config Manager: If you're using the Polling Config Manager, provide your custom cache implementation in the config.
  2. Batch Event Processor: If you're 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.