> 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/ja-gitbook-documentation/publish/adaptive-content/enabling-adaptive-content/feature-flags.md).

# 機能フラグ

機能フラグプロバイダーを通じて、訪問者データをドキュメントに渡します

{% hint style="warning" %}
アダプティブコンテンツを機能フラグと併用するには、アプリケーションにコードを追加する必要があります。

現在、GitBook ヘルパーは 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 ヘルパーをアプリケーションにインストールして追加する**

LaunchDarkly の統合を設定した後、GitBook のアプリケーションに GitBook の adaptive content ヘルパーをインストールする必要があります。

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

{% endstep %}

{% step %}
**アプリケーションを設定する**

次を使用する必要があります： `withLaunchDarkly` 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 %}
**visitor スキーマを確認する**

1つの [visitor スキーマ](/docs/documentation/ja-gitbook-documentation/publish/adaptive-content/enabling-adaptive-content.md#set-your-visitor-schema) 公開サイトでクレームを読み取れるようにするには必須です。LaunchDarkly の統合をインストールして設定すると、visitor スキーマは自動的に設定されるはずです。
{% endstep %}

{% step %}
**コンテンツをパーソナライズする**

visitor スキーマを設定したら、ユーザーがアクセスできるフィーチャーフラグを使って、サイトを訪れるユーザー向けにドキュメント体験を調整できるようになります。

LaunchDarkly で利用可能なフィーチャーフラグの値はすべて、visitor スキーマの一部として次の下に公開されます： `visitor.claims.unsigned.launchdarkly` オブジェクト。署名なしクレームの詳細を見る [こちら](/docs/documentation/ja-gitbook-documentation/publish/adaptive-content/enabling-adaptive-content.md#set-an-unsigned-claim).

に移動します [コンテンツの適応](/docs/documentation/ja-gitbook-documentation/publish/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 ヘルパーをアプリケーションにインストールする**

Reflag の統合を設定した後、GitBook のアプリケーションに GitBook の adaptive content ヘルパーをインストールする必要があります。

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

{% endstep %}

{% step %}
**アプリケーションを設定する**

次を使用する必要があります： `withReflag` 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 %}
**visitor スキーマを確認する**

1つの [visitor スキーマ](/docs/documentation/ja-gitbook-documentation/publish/adaptive-content/enabling-adaptive-content.md#set-your-visitor-schema) 公開サイトでクレームを読み取れるようにするには必須です。Reflag の統合をインストールして設定すると、visitor スキーマは自動的に設定されるはずです。
{% endstep %}

{% step %}
**コンテンツをパーソナライズする**

visitor スキーマを設定したら、ユーザーがアクセスできるフィーチャーフラグを使って、サイトを訪れるユーザー向けにドキュメント体験を調整できるようになります。

Reflag で利用可能なフィーチャーフラグの値はすべて、visitor スキーマの一部として次の下に公開されます： `visitor.claims.unsigned.reflag` オブジェクト。署名なしクレームの詳細を見る [こちら](/docs/documentation/ja-gitbook-documentation/publish/adaptive-content/enabling-adaptive-content.md#set-an-unsigned-claim).

に移動します [コンテンツの適応](/docs/documentation/ja-gitbook-documentation/publish/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/publish/adaptive-content/enabling-adaptive-content/feature-flags.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
