This is a POC on how to install and use Optimizely React SDK with Expo.
This POC is based on Expo SDK 50. Setup might differ from version to version. If you face any trouble setting up the SDK, please create an issue under the Optimizely React SDK issue
Create a .env.local
file. Put you SDK key
EXPO_PUBLIC_OPTIMIZELY_SDK_KEY="<YOUR_SDK_KEY>"
Check out Optimizely React native official installation guide
All the necessary dependencies have been installed and included in this project. To install required dependencies, run -
npm install
For exising app, do followings.
Install @optimizely/react-sdk
.
npm install --save @optimizely/react-sdk
Install peer dependencies as well -
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 required to:- Enable datafile caching by storing the datafile on the user's device.
- Enable event offline persistence by temporarily storing events on the 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.react-native-get-random-values
is required for crypto.getRandomValues() support.fast-text-encoding
is required to support encoding for user bucketing.
You can run the app both in Expo Go or with the help of development build.
We prefer development build. And following demonstration is on how to build and run the app in a development build -
# Android: follow eas.json for profile config
eas build --profile development --platform android
# IOS: follow eas.json for profile config
eas build --profile development-simulator --platform ios
Run following command in your project directory, and open the development build in a device -
# Android
npm run android
# IOS
npm run ios