Skip to content

Commit 695b688

Browse files
authored
update readme (#45)
1 parent 2194d45 commit 695b688

File tree

1 file changed

+122
-1
lines changed

1 file changed

+122
-1
lines changed

README.md

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,122 @@
1-
# react-native-sdk
1+
# Eppo React Native SDK
2+
3+
[![Test and lint SDK](https://github.com/Eppo-exp/react-native-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/Eppo-exp/react-native-sdk/actions/workflows/ci.yml)
4+
5+
[Eppo](https://www.geteppo.com/) is a modular flagging and experimentation analysis tool. Eppo's React Native SDK is built to make assignments for single user client applications that run in a web browser. Before proceeding you'll need an Eppo account.
6+
7+
## Features
8+
9+
- Feature gates
10+
- Kill switches
11+
- Progressive rollouts
12+
- A/B/n experiments
13+
- Mutually exclusive experiments (Layers)
14+
- Dynamic configuration
15+
16+
## Installation
17+
18+
```bash
19+
npm install @eppo/react-native-sdk
20+
```
21+
22+
## Quick start
23+
24+
Begin by initializing a singleton instance of Eppo's client. Once initialized, the client can be used to make assignments anywhere in your app.
25+
26+
#### Initialize once
27+
28+
```javascript
29+
import { init } from "@eppo/react-native-sdk";
30+
31+
await init({ apiKey: "<SDK-KEY-FROM-DASHBOARD>" });
32+
```
33+
34+
35+
#### Assign anywhere
36+
37+
```javascript
38+
import * as EppoSdk from "@eppo/react-native-sdk";
39+
40+
const eppoClient = EppoSdk.getInstance();
41+
const user = getCurrentUser();
42+
43+
const variation = eppoClient.getBooleanAssignment('show-new-feature', user.id, {
44+
'country': user.country,
45+
'device': user.device,
46+
}, false);
47+
```
48+
49+
## Assignment functions
50+
51+
Every Eppo flag has a return type that is set once on creation in the dashboard. Once a flag is created, assignments in code should be made using the corresponding typed function:
52+
53+
```javascript
54+
getBoolAssignment(...)
55+
getNumericAssignment(...)
56+
getIntegerAssignment(...)
57+
getStringAssignment(...)
58+
getJSONAssignment(...)
59+
```
60+
61+
Each function has the same signature, but returns the type in the function name. For booleans use `getBooleanAssignment`, which has the following signature:
62+
63+
```javascript
64+
getBooleanAssignment: (
65+
flagKey: string,
66+
subjectKey: string,
67+
subjectAttributes: Record<string, any>,
68+
defaultValue: boolean,
69+
) => boolean
70+
```
71+
72+
## Initialization options
73+
74+
The `init` function accepts the following optional configuration arguments.
75+
76+
| Option | Type | Description | Default |
77+
| ------ | ----- | ----- | ----- |
78+
| **`assignmentLogger`** | [IAssignmentLogger](https://github.com/Eppo-exp/react-native-sdk-common/blob/75c2ea1d91101d579138d07d46fca4c6ea4aafaf/src/assignment-logger.ts#L55-L62) | A callback that sends each assignment to your data warehouse. Required only for experiment analysis. See [example](#assignment-logger) below. | `null` |
79+
| **`requestTimeoutMs`** | number | Timeout in milliseconds for HTTPS requests for the experiment configurations. | `5000` |
80+
| **`numInitialRequestRetries`** | number | Number 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. | `1` |
81+
| **`pollAfterSuccessfulInitialization`** | boolean | Poll for new configurations (every 30 seconds) after successfully requesting the initial configurations. | `false` |
82+
| **`pollAfterFailedInitialization`** | boolean | Poll for new configurations even if the initial configurations request failed. | `false` |
83+
| **`throwOnFailedInitialization`** | boolean | Throw an error (reject the promise) if unable to fetch initial configurations during initialization. | `true` |
84+
| **`numPollRequestRetries`** | number | If 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. | `7` |
85+
86+
87+
88+
## Assignment logger
89+
90+
To use the Eppo SDK for experiments that require analysis, pass in a callback logging function to the `init` function on SDK initialization. The SDK invokes the callback to capture assignment data whenever a variation is assigned. The assignment data is needed in the warehouse to perform analysis.
91+
92+
The code below illustrates an example implementation of a logging callback using [Segment](https://segment.com/), but you can use any system you'd like. The only requirement is that the SDK receives a `logAssignment` callback function. Here we define an implementation of the Eppo `IAssignmentLogger` interface containing a single function named `logAssignment`:
93+
94+
```javascript
95+
import { IAssignmentLogger } from "@eppo/react-native-sdk";
96+
import { AnalyticsBrowser } from "@segment/analytics-next";
97+
98+
// Connect to Segment (or your own event-tracking system)
99+
const analytics = AnalyticsBrowser.load({ writeKey: "<SEGMENT_WRITE_KEY>" });
100+
101+
const assignmentLogger: IAssignmentLogger = {
102+
logAssignment(assignment) {
103+
analytics.track({
104+
userId: assignment.subject,
105+
event: "Eppo Randomized Assignment",
106+
type: "track",
107+
properties: { ...assignment },
108+
});
109+
},
110+
};
111+
```
112+
113+
#### Avoiding duplicated assignment logs
114+
115+
Eppo's SDK uses an internal cache to ensure that duplicate assignment events are not logged to the data warehouse. While Eppo's analytic engine will automatically deduplicate assignment records, this internal cache prevents firing unnecessary events and can help minimize costs associated with event logging.
116+
117+
## Philosophy
118+
119+
Eppo's SDKs are built for simplicity, speed and reliability. Flag configurations are compressed and distributed over a global CDN (Fastly), typically reaching end users in under 15ms. Those configurations are then cached locally, ensuring that each assignment is made instantly. Each SDK is as light as possible, with evaluation logic at around [25 simple lines of code](https://github.com/Eppo-exp/react-native-sdk-common/blob/b903bbbca21ca75c0ab49d894951eb2f1fc6c85b/src/evaluator.ts#L34-L59). The simple typed functions listed above are all developers need to know about, abstracting away the complexity of the underlying set of features.
120+
121+
122+

0 commit comments

Comments
 (0)