> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content/feature-flags.md).

# 功能标志

通过功能标志提供程序将访客数据传入你的文档

{% hint style="warning" %}
在功能标志中使用自适应内容需要向你的应用程序添加代码。

目前，GitBook helper 仅支持基于 React 的设置。
{% endhint %}

GitBook 提供用于以下流行功能标记服务提供商的辅助函数和集成： [**LaunchDarkly**](#launchdarkly) 以及 [**Reflag**](#reflag).

这使你能够在用户阅读文档时读取他们在产品中可访问的功能标记。如果你需要为仅对特定人群可用的功能显示文档，这会很有用。

### LaunchDarkly

LaunchDarkly 允许你通过以下方式将功能标记访问权限作为声明发送： [`launchdarkly-react-client-sdk`](https://launchdarkly.com/docs/sdk/client-side/react/react-web) 以及 GitBook 的 [`@gitbook/adaptive`](broken://spaces/zq8ynchcecIscc4uulgN) 包。

如果你已经在产品中使用 LaunchDarkly 功能标记，那么你很可能已经配置好了这个包。

要将这些功能标记作为声明传递给 GitBook，请按照以下步骤操作：

{% stepper %}
{% step %}
**安装 LaunchDarkly 集成**

要开始使用，你首先需要 [安装 LaunchDarkly 集成](https://app.gitbook.com/integrations/launchdarkly) 到你的 GitBook 站点中。
{% endstep %}

{% step %}
**设置你的项目和访问密钥**

将你的项目密钥和来自以下位置的服务访问令牌添加到： [LaunchDarkly 设置](https://app.launchdarkly.com/settings) 到该集成的配置中。
{% endstep %}

{% step %}
**将 GitBook helper 安装并添加到你的应用程序中**

在设置好 LaunchDarkly 集成后，你需要在应用程序中安装 GitBook 自适应内容 helper。

```bash
npm install @gitbook/adaptive
```

{% endstep %}

{% step %}
**配置你的应用程序**

你需要使用 `withLaunchDarkly` helper 与 LaunchDarkly React SDK 一起使用，以将上下文传递给 GitBook。

<pre class="language-javascript"><code class="lang-javascript">import { render } from 'react-dom';
<strong>import { withLaunchDarkly } from '@gitbook/adaptive';
</strong><strong>import { asyncWithLDProvider, useLDClient } from 'launchdarkly-react-client-sdk';
</strong>import MyApplication from './MyApplication';

function PassFeatureFlagsToGitBookSite() {
<strong>    const ldClient = useLDClient();
</strong>    React.useEffect(() => {
        if (!ldClient) {
            return;
        }
<strong>        return withLaunchDarkly(ldClient);
</strong>    }, [ldClient]);
    return null;
}
(async () => {
    const LDProvider = await asyncWithLDProvider({
        clientSideID: 'client-side-id-123abc',
        context: {
            kind: 'user',
            key: 'user-key-123abc',
            name: 'Sandy Smith',
            email: 'sandy@example.com'
        },
        options: { /* ... */ }
    });
    render(
        &#x3C;LDProvider>
            &#x3C;PassFeatureFlagsToGitBookSite />
            &#x3C;MyApplication />
        &#x3C;/LDProvider>,
        document.getElementById('reactDiv'),
    );
})();
</code></pre>

{% endstep %}

{% step %}
**检查你的访客 schema**

一笔 [访客 schema](/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content.md#set-your-visitor-schema) 是你的声明能够在已发布站点中被读取所必需的。安装并配置 LaunchDarkly 集成应会自动为你设置访客 schema。
{% endstep %}

{% step %}
**个性化你的内容**

在设置好访客 schema 后，你就可以使用用户可访问的功能标记，为访问你站点的用户定制文档体验。

任何在 LaunchDarkly 中可用的功能标记值都会作为访客 schema 的一部分暴露在 `visitor.claims.unsigned.launchdarkly` 对象下。了解更多关于未签名声明的信息 [这里](/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content.md#set-an-unsigned-claim).

前往 [调整你的内容](/docs/documentation/zh/fa-bu/adaptive-content/adapting-your-content.md) 以了解更多如何为你的用户个性化文档。
{% endstep %}
{% endstepper %}

### Reflag

Reflag 允许你通过以下方式将功能标记访问权限作为声明发送： [`@reflag/react-sdk`](https://www.npmjs.com/package/@reflag/react-sdk) 以及 GitBook 的 [`@gitbook/adaptive`](https://github.com/GitbookIO/integrations/tree/main/packages/adaptive) 包。

如果你已经在产品中使用 Reflag 功能标记，那么你很可能已经配置好了这个包。

要将这些功能标记作为声明传递给 GitBook，请按照以下步骤操作：

{% stepper %}
{% step %}
**安装 Reflag 集成**

要开始使用，你首先需要 [安装 Reflag 集成](https://app.gitbook.com/integrations/bucket) 到你的 GitBook 站点中。
{% endstep %}

{% step %}
**设置你的密钥**

将来自以下位置的密钥添加到： [Reflag 设置](https://app.reflag.com/envs/current/settings/app-environments) 到该集成的配置中。
{% endstep %}

{% step %}
**将 GitBook helper 安装到你的应用程序中**

在设置好 Reflag 集成后，你需要在应用程序中安装 GitBook 自适应内容 helper。

```bash
npm install @gitbook/adaptive
```

{% endstep %}

{% step %}
**配置你的应用程序**

你需要使用 `withReflag` helper 与 Reflag React SDK 一起使用，以将上下文传递给 GitBook。

<pre class="language-javascript"><code class="lang-javascript"><strong>import { withReflag } from '@gitbook/adaptive';
</strong><strong>import { ReflagProvider, useClient } from '@reflag/react-sdk';
</strong>import MyApplication from './MyApplication';

function PassFeatureFlagsToGitBookSite() {
<strong>    const client = useClient();
</strong>    React.useEffect(() => {
        if (!client) {
            return;
        }
<strong>        return withReflag(client);
</strong>    }, [client]);
    return null;
}
export function Application() {
    const currentUser = useLoggedInUser();
    const appConfig = useAppConfig();
    return (
        &#x3C;ReflagProvider
            publishableKey={appConfig.reflagCom.publishableKey}
            user={{
                id: currentUser.uid,
                email: currentUser.email ?? undefined,
                name: currentUser.displayName ?? '',
            }}
            company={{
                id: currentUser.company.id,
            }}
        >
            &#x3C;PassFeatureFlagsToGitBookSite />
            &#x3C;MyApplication />
        &#x3C;/ReflagProvider>
    );
}
</code></pre>

{% endstep %}

{% step %}
**检查你的访客 schema**

一笔 [访客 schema](/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content.md#set-your-visitor-schema) 是你的声明能够在已发布站点中被读取所必需的。安装并配置 Reflag 集成应会自动为你设置访客 schema。
{% endstep %}

{% step %}
**个性化你的内容**

在设置好访客 schema 后，你就可以使用用户可访问的功能标记，为访问你站点的用户定制文档体验。

任何在 Reflag 中可用的功能标记值都会作为访客 schema 的一部分暴露在 `visitor.claims.unsigned.reflag` 对象下。了解更多关于未签名声明的信息 [这里](/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content.md#set-an-unsigned-claim).

前往 [调整你的内容](/docs/documentation/zh/fa-bu/adaptive-content/adapting-your-content.md) 以了解更多如何为你的用户个性化文档。
{% endstep %}
{% endstepper %}

{% hint style="info" %}
功能标记值会在客户端进行评估，因此请避免使用此方法传递敏感或与安全相关的关键数据。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content/feature-flags.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
