> ## Documentation Index
> Fetch the complete documentation index at: https://docs.molesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RUM 功能开关

> 看会话算过哪些功能开关，并对比每个取值下会话的情况。

告诉 SDK 一个开关算出来的值，这个视图的每个事件都会带上它：

```ts theme={null}
molesignalRum.addFeatureFlagEvaluation('checkout_v2', 'treatment');
```

跟随开关服务时把算值的结果传进来。LaunchDarkly 用 inspector，OpenFeature 用 hook：

```ts theme={null}
LDClient.initialize(id, user, {
  inspectors: [{
    type: 'flag-used',
    name: 'molesignal',
    method: (key, detail) => molesignalRum.addFeatureFlagEvaluation(key, detail.value),
  }],
});

OpenFeature.addHooks({
  after: (context, details) => molesignalRum.addFeatureFlagEvaluation(context.flagKey, details.value),
});
```

## 功能开关页

**功能开关** 列出这段时间会话算过的开关，碰到它的会话最多的在前。选一个开关就能并排对比它的取值：会话数、有错误的视图比例、有受挫信号的视图比例，浏览器应用还有 LCP、INP、CLS 的 75 分位。有错误的视图比例最高的取值标红。**看这些视图** 在探索页打开它们。

## 在任何地方按开关查询

开关的名字像列一样写成 `feature_flags.<key>`，[探索页](https://docs.molesignal.com/zh-Hans/rum/explorer.md)和 API 接受字段的地方都能用：

```text theme={null}
feature_flags.checkout_v2 = 'treatment' AND error.type = 'TypeError'
```

```http theme={null}
POST /api/v1/rum/aggregate
{ "type": "views", "measures": [{ "fn": "p75", "field": "view.performance.lcp.timestamp" }], "group_by": ["feature_flags.checkout_v2"] }
```

JSON 列里的其他键也一样：`context.<key>`、`usr.extra.<key>`、`view.custom_timings.<key>`。`GET /api/v1/rum/keys` 列出有哪些键。

写 SQL 时用 `json_text("feature_flags", 'checkout_v2')` 读一个键，结果是文本，这一行没有这个键时是 NULL。`json_keys("feature_flags")` 列出一行的键。

## Mole Agent

工具 `get_rum_feature_flags` 列出开关；给定 `flag` 时用同样的数字对比它的取值。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.