> 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.md).

# 启用自适应内容

选择一种身份验证方法将用户数据传递给 GitBook。

要开始为读者自定义你的文档体验，你需要启用自适应内容，并决定访客数据如何传递给 GitBook。这样你的网站内容就能根据访问者动态调整。

### 启用自适应内容

在你能够将用户数据传递给 GitBook 之前，你需要配置你的网站以使用自适应内容。

前往你的 [网站设置](/docs/documentation/zh/guan-li-ni-de-zhan-dian/site-settings.md)，并启用 **自适应内容** 来自你网站的受众设置。启用后，你将获得一个生成的“访客令牌签名密钥”，你需要它才能继续进行自适应内容设置。

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2F5EeWAo5Ij6CKrp69uMl5%2F26_01_06_enable_adaptive_content%402x.png?alt=media&amp;token=4a1e8558-4b91-4f8b-8581-63d570a2c330" alt="A GitBook screenshot showing the enable adaptive content toggle"><figcaption><p>在你网站的设置中启用自适应内容</p></figcaption></figure>

### 设置你的访客架构

启用自适应内容后，你需要为当用户访问你的网站时 GitBook 预期接收的声明类型定义一个架构。

访客架构应反映这些声明发送到 GitBook 时的结构方式。

例如，如果你预计访客在你的产品中可能是测试版用户，你可以设置类似如下的访客架构：

```json
{
  "type": "object",
  "properties": {
    "isBetaUser": {
      "type": "boolean",
      "description": "访客是否为测试版用户。"
    }
  },
  "additionalProperties": false
}
```

这也会帮助你在配置声明时使用自动补全， [条件编辑器](/docs/documentation/zh/fa-bu/adaptive-content/adapting-your-content.md#working-with-the-condition-editor). 访客架构仅支持以下类型：

{% tabs %}
{% tab title="字符串" %}
读取作为字符串传入的声明。

GitBook 支持动态字符串，这意味着你可以动态传递字符串数据——例如用户姓名、开发者令牌等。

字符串还可以包含一个 **可选的枚举** 键，这使你可以将 GitBook 接收到的数据限制为其预设值之一。

```json
{
  "type": "object",
  "properties": {
    "language": {
          "type": "string",
          "description": "访客的语言",
          // 可选的枚举属性
          "enum": [
            "en",
            "fr",
            "it"
          ]
  },
  "additionalProperties": false
}
```

{% hint style="warning" %}
动态字符串（未定义 enum 键的字符串）仅适用于 [行内表达式](/docs/documentation/zh/chuang-jian-nei-rong/variables-and-expressions.md#use-variables-in-your-content). 元素（页面、章节、块）可见性的条件表达式仅适用于使用 enum 键定义的字符串。
{% endhint %}
{% endtab %}

{% tab title="布尔值" %}
读取作为布尔值传入的声明。

```json
{
  "type": "object",
  "properties": {
    "isBetaUser": {
      "type": "boolean",
      "description": "访客是否为测试版用户。"
    },
  },
  "additionalProperties": false
}
```

{% endtab %}

{% tab title="对象" %}
将声明嵌套在对象中，以分组相似的值。

```json
{
  // 顶层声明
  "type": "object",
  "properties": {
    // 嵌套声明
    "access": {
      "type": "object",
      "description": "用户对产品功能的访问权限",
      "properties": {
        "isAlphaUser": {
          "type": "boolean",
          "description": "访客是否为 Alpha 用户。"
        },
        "isBetaUser": {
          "type": "boolean",
          "description": "访客是否为测试版用户。"
        },
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
```

{% endtab %}
{% endtabs %}

### 设置未签名声明

未签名声明是一种特定类型的声明，用于识别可能未经过客户端应用签名传入的声明。如果你要通过以下方式传递声明，则需要在访客架构中将声明设置为 `未签名的` 如果你通过 URL 参数、未签名 cookie 和功能标志传递声明。

如果你打算使用未签名声明，你需要在架构中的“unsigned”属性下，将你预期接收的声明与已签名声明并列声明。

```json
{
  "type": "object",
  "properties": {
    "isBetaUser": {
      "type": "boolean",
      "description": "访客是否为测试版用户。"
    },
    // 添加未签名声明
    "unsigned": {
      "type": "object",
      "description": "站点访客的未签名声明。",
      "properties": {
        "language": {
          "type": "string",
          "description": "访客的语言",
          // 可选的枚举属性
          "enum": [
            "en",
            "fr",
            "it"
          ]
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
```

### 将访客数据传递给 GitBook

GitBook 提供多种方式来传递访客数据，以便调整你网站的内容。定义好架构后，你需要决定希望如何将访客数据传递给 GitBook。

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><i class="fa-cookie">:cookie:</i></td><td><strong>Cookie</strong></td><td>通过公开 cookie 或签名 cookie 将访客数据传入你的文档。</td><td><a href="/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content/cookies.md">Cookie</a></td></tr><tr><td><i class="fa-link">:link:</i></td><td><strong>URL</strong></td><td>通过 URL 查询参数将访客数据传入你的文档。</td><td><a href="/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content/url.md">URL</a></td></tr><tr><td><i class="fa-flag">:flag:</i></td><td><strong>功能标志</strong></td><td>通过功能标志提供方将访客数据传入你的文档。</td><td><a href="/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content/feature-flags.md">功能标志</a></td></tr><tr><td><i class="fa-lock">:lock:</i></td><td><strong>经过身份验证的访问</strong></td><td>通过身份验证提供方将访客数据传入你的文档。</td><td><a href="/docs/documentation/zh/fa-bu/adaptive-content/enabling-adaptive-content/authenticated-access.md">已认证访问</a></td></tr></tbody></table>


---

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