# 启用自适应内容

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

### 启用自适应内容

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

前往你的 [站点设置](/docs/documentation/zh/docs-site/site-settings.md)，并启用 **自适应内容** ，在你网站的受众设置中。启用后，你会得到一个生成的“Visitor token signing key（访客令牌签名密钥）”，你需要它才能继续进行自适应内容设置。

<figure><img src="/files/5c67c30d0e5388060ca38ad9090f37f030202433" alt="A GitBook screenshot showing the enable adaptive content toggle"><figcaption><p>在你网站的设置中启用自适应内容</p></figcaption></figure>

### 设置访客 schema

启用自适应内容后，你需要为你希望 GitBook 在用户访问你的网站时接收的声明类型定义一个 schema。

访客 schema 应反映这些声明在发送到 GitBook 时的结构。

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

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

这也将帮助你在配置以下内容中的声明时使用自动补全 [条件编辑器](/docs/documentation/zh/zhan-dian-fang-wen/adaptive-content/adapting-your-content.md#working-with-the-condition-editor)。访客 schema 仅支持以下类型：

{% tabs %}
{% tab title="字符串" %}
读取以字符串形式传入的声明。

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

字符串还可以包含一个 **可选的 enum** 键，它允许你将 GitBook 接收的数据限制为其设定值之一。

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

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

{% tab title="布尔值" %}
读取以布尔值形式传入的声明。

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

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

### 设置未签名声明

未签名声明是一种特定类型的声明，用于识别可能未由客户端应用签名传入的声明。如果你通过 URL 参数、未签名 cookie 和功能标志传递声明，就必须在访客 schema 中将声明设置为 `未签名的` if you are passing claims through URL parameters, unsigned cookies, and feature flags.

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

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

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

GitBook 提供了多种方式将访客数据传递进去，以便调整你网站的内容。定义好 schema 后，你需要决定希望如何将访客数据传递给 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 将访客数据传递到你的文档中。</td><td><a href="/pages/3eabf4988eba042e3bb52b5f99d096e4c132203f">/pages/3eabf4988eba042e3bb52b5f99d096e4c132203f</a></td></tr><tr><td><i class="fa-link">:link:</i></td><td><strong>URL</strong></td><td>通过 URL 查询参数将访客数据传递到你的文档中。</td><td><a href="/pages/90609aa22a514121df99171942c7c9fba3c1015f">/pages/90609aa22a514121df99171942c7c9fba3c1015f</a></td></tr><tr><td><i class="fa-flag">:flag:</i></td><td><strong>功能标志</strong></td><td>通过功能标志提供方将访客数据传递到你的文档中。</td><td><a href="/pages/9d0f52929e25a06b01f2ad71866517ed65c1b7f4">/pages/9d0f52929e25a06b01f2ad71866517ed65c1b7f4</a></td></tr><tr><td><i class="fa-lock">:lock:</i></td><td><strong>身份验证访问</strong></td><td>通过身份验证提供方将访客数据传递到你的文档中。</td><td><a href="/pages/6dff1bce75f1a28203dee5306f48ffdd321c136a">/pages/6dff1bce75f1a28203dee5306f48ffdd321c136a</a></td></tr></tbody></table>


---

# Agent Instructions: 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:

```
GET https://gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/adaptive-content/enabling-adaptive-content.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
