Initialization
The Eppo JavaScript SDK is easy to initialize while offering robust customization options, making it adaptable to various use cases such as offline mode, custom caching requirements, and ultra-low-latency initialization.
Initialize the SDK
To complete basic initialization, you only need to provide an SDK key. Create an SDK key if you don't already have one.
import { init } from "@eppo/react-native-sdk";
await init({
apiKey: 'tx6eTRdJh2MD0KV87FB2aQ1uNMhGpzJmucQRifMtvGE',
assignmentLogger: { logAssignment: (assignment: IAssignmentEvent)=> console.log('TODO: send to warehouse', assignment) }
})
Use the SDK instance
After initialization, you can use the SDK instance by importing the SDK at the scope you will use it in and calling getInstance(). You can then use the SDK instance to assign a variation to a subject using the get*Assignment functions.
import * as EppoSdk from "@eppo/react-native-sdk";
const eppoClient = EppoSdk.getInstance();
Advanced Configuration
Basic initialization is great for most use cases, but the SDK provides options that you can use during initialization to customize the behavior of the SDK.
Initialization Options
How the SDK fetches, serves, and caches experiment configurations is configurable via additional optional initialization options:
requestTimeoutMsnumberDefault: 5000Timeout in milliseconds for HTTPS requests for the experiment configurations.
numInitialRequestRetriesnumberDefault: 1Number of additional times the initial configurations request will be attempted if it fails.
This is the request typically synchronously waited (via await) for completion.
A small wait will be done between requests.
baseUrlstringDefault: https://api.eppo.comThe base URL for for the API. Can be overriden to proxy configuration requests.
pollAfterSuccessfulInitializationbooleanDefault: falsePoll for a new configuration (every 30 seconds or as set in pollingIntervalMs) after successfully requesting the initial configurations.
pollAfterFailedInitializationbooleanDefault: falsePoll for new configurations even if the initial configurations request failed.
pollingIntervalMsnumberDefault: 30000Maximum amount of time to wait between calls to the API for the latest configuration if polling is enabled.
throwOnFailedInitializationbooleanDefault: trueThrow an error (reject the promise) if unable to fetch initial configurations during initialization.
numPollRequestRetriesnumberDefault: 7If polling for updated configurations after initialization, the number of additional times a request will be attempted before giving up. Subsequent attempts are done using an exponential backoff.
persistentStoreIAsyncStoreDefault: (Eppo provided)An asynchronous, persistent storage for caching fetched flag configurations for use in subsequent sessions
maxCacheAgeSecondsnumberDefault: 0Maximum age, in seconds, that a previously cached configuration is considered valid and the wait-time before fetching a fresh configuration