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

Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Install SDK

This topic describes the steps necessary to install the Optimizely JavaScript (React) SDK.

The React Native SDK can be used in both ReactJS and React Native environments, and is distributed through npm. The React SDK supports datafile caching and offline events persistence for React Native applications. Add it to your package with NPM:

npm install --save @optimizely/react-sdk

or with Yarn:

yarn add @optimizely/react-sdk

The full source code is at https://github.com/optimizely/react-sdk.

Requirements

The React SDK requires an ES5-compatible environment, as well as Promise. To run in environments that don't support promise, you can use promise-polyfill.

Peer dependencies

To use the features such as datafile caching and offline events persistence, you need to install the following peer dependencies in your React Native application.

yarn add @react-native-async-storage/async-storage @react-native-community/netinfo
npm install --save @react-native-async-storage/async-storage @react-native-community/netinfo

@react-native-async-storage/async-storage is required to:

  • enable datafile caching by storing the datafile on the user's device.
  • enable event offline persistence by temporarily storing events on user's device when offline.

@react-native-community/netinfo is required to detect when internet connectivity is restored, so that events triggered during the offline mode can be retried.