@eppo/react-native-sdk

中文文档
3.8.0发布于 2025/04/03MITTypeScriptESM + CJS近 30 天下载 4.6万

Eppo React Native SDK

原始使用文档
文档目录7 节
  1. Features
  2. Installation
  3. Quick start
  4. Assignment functions
  5. Initialization options
  6. Assignment logger
  7. Philosophy

Eppo React Native SDK

Test and lint SDK

Eppo 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.

Features

  • Feature gates
  • Kill switches
  • Progressive rollouts
  • A/B/n experiments
  • Mutually exclusive experiments (Layers)
  • Dynamic configuration

Installation

npm install @eppo/react-native-sdk

Quick start

Begin by initializing a singleton instance of Eppo's client. Once initialized, the client can be used to make assignments anywhere in your app.

Initialize once

import { init } from "@eppo/react-native-sdk";

await init({ apiKey: "<SDK-KEY-FROM-DASHBOARD>" });

Assign anywhere

import * as EppoSdk from "@eppo/react-native-sdk";

const eppoClient = EppoSdk.getInstance();
const user = getCurrentUser();

const variation = eppoClient.getBooleanAssignment('show-new-feature', user.id, { 
  'country': user.country,
  'device': user.device,
}, false);

Assignment functions

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:

getBoolAssignment(...)
getNumericAssignment(...)
getIntegerAssignment(...)
getStringAssignment(...)
getJSONAssignment(...)

Each function has the same signature, but returns the type in the function name. For booleans use getBooleanAssignment, which has the following signature:

getBooleanAssignment: (
  flagKey: string,
  subjectKey: string,
  subjectAttributes: Record<string, any>,
  defaultValue: boolean,
) => boolean

Initialization options

The init function accepts the following optional configuration arguments.

OptionTypeDescriptionDefault
assignmentLoggerIAssignmentLoggerA callback that sends each assignment to your data warehouse. Required only for experiment analysis. See example below.null
requestTimeoutMsnumberTimeout in milliseconds for HTTPS requests for the experiment configurations.5000
numInitialRequestRetriesnumberNumber 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
pollAfterSuccessfulInitializationbooleanPoll for new configurations (every 30 seconds) after successfully requesting the initial configurations.false
pollAfterFailedInitializationbooleanPoll for new configurations even if the initial configurations request failed.false
throwOnFailedInitializationbooleanThrow an error (reject the promise) if unable to fetch initial configurations during initialization.true
numPollRequestRetriesnumberIf 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

Assignment logger

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.

The code below illustrates an example implementation of a logging callback using Segment, 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:

import { IAssignmentLogger } from "@eppo/react-native-sdk";
import { AnalyticsBrowser } from "@segment/analytics-next";

// Connect to Segment (or your own event-tracking system)
const analytics = AnalyticsBrowser.load({ writeKey: "<SEGMENT_WRITE_KEY>" });

const assignmentLogger: IAssignmentLogger = {
  logAssignment(assignment) {
    analytics.track({
      userId: assignment.subject,
      event: "Eppo Randomized Assignment",
      type: "track",
      properties: { ...assignment },
    });
  },
};

Avoiding duplicated assignment logs

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.

Philosophy

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. The simple typed functions listed above are all developers need to know about, abstracting away the complexity of the underlying set of features.

版本与发布记录

@eppo/react-native-sdk 共发布 29 个版本,首次发布于 2023/04/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.8.0latest2025/04/031.6 年前
3.7.42025/03/211.7 年前
3.7.32025/03/131.7 年前
3.7.3-alpha.0alpha.02025/03/131.7 年前
3.7.22025/03/131.7 年前
3.7.12025/03/121.7 年前

其他发布通道:rc → 3.4.0-rc.1,alpha.0 → 3.7.3-alpha.0。

关于 @eppo/react-native-sdk 的常见问题

@eppo/react-native-sdk 是什么?

Eppo React Native SDK

如何安装 @eppo/react-native-sdk?

在项目目录运行 npm install @eppo/react-native-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@eppo/react-native-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eppo/react-native-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@eppo/react-native-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@eppo/react-native-sdk 可以商用吗?

@eppo/react-native-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eppo/react-native-sdk 的下载量有多少?

根据 npm 官方下载统计,@eppo/react-native-sdk 在 2026/10/14 – 2026/11/12 这 30 天内被下载 45,835 次,日均约 1,528 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eppo/react-native-sdk 还在维护吗?

最新版本 3.8.0 发布于 2025/04/03(1.6 年前);至今共发布 29 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/04/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。