> 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/publish/embedding.md).

# 嵌入到你的产品中

使用 Docs Embed 将你的文档嵌入到产品或网站中。

文档嵌入是一个强大的窗口，可让你将产品知识添加到任何产品或网站中。用户可以向 [GitBook 助手](https://gitbook.com/docs/documentation/zh/ai-for-your-readers/gitbook-ai-assistant.md)提问、搜索文档或直接浏览页面，无需离开你的产品。你可以通过按钮打开嵌入，将其放入所需的任何组件中，也可以完全通过编程方式控制它。

<div data-with-frame="true"><figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-47120dd47f43cd781d9f5da4f34c80039fd765fa%2F25_10_21_emebeddable_assistant.png?alt=media" alt="Embed GitBook Assistant into your product or website"><figcaption><p>将你的文档嵌入到你的产品或网站中</p></figcaption></figure></div>

## 概览

Docs Embed 可包含三个选项卡：

* **助手**： [GitBook 助手](https://gitbook.com/docs/documentation/zh/ai-for-your-readers/gitbook-ai-assistant.md) — 一个由 AI 驱动的聊天界面，帮助用户查找答案
* **搜索**：以搜索为核心的界面，可快速查找页面并提出范围限定的问题
* **文档**：用于浏览文档站点的浏览器

默认情况下会启用所有标签页。如果设置了 `tabs`，嵌入只会显示你列出的标签页。

你可以通过自定义操作、工具、建议问题、 [身份验证访问](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access.md)等自定义并覆盖默认配置。

## 开始使用

{% stepper %}
{% step %}
**前置条件**

在嵌入你的文档之前，请确保：

1. **你的文档已发布，** 并可通过 URL 访问（例如， `https://docs.company.com`).
2. **你已从站点设置中获取嵌入脚本 URL** （设置 → AI 与 MCP → 嵌入）。

{% hint style="info" %}
如果你想使用“助手”标签页， [必须为你的文档站点启用 GitBook 助手](https://gitbook.com/docs/documentation/zh/ai-for-your-readers/gitbook-ai-assistant.md) （设置 → AI 与 MCP）。
{% endhint %}
{% endstep %}

{% step %}
**实现方式**

使用我们的技能，借助你现有的技术栈快速将 GitBook Assistant 集成到你的产品中。

{% file src="/files/660b98bf335fdae37957dad219a2cfe40afb63cb" %}

或者，继续阅读文档，选择适合你配置的方案：

<table 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-code">:code:</i></td><td><strong>独立脚本标签</strong></td><td>插入一个 &#x3C;script> 标签即可完成最快速的设置，然后自定义其外观</td><td><a href="https://gitbook.com/docs/documentation/zh/publish/embedding/implementation/script.md">脚本标签</a></td></tr><tr><td><i class="fa-box">:box:</i></td><td><strong>Node.js/NPM</strong></td><td>通过 NPM 安装，以便进行服务端渲染或构建时控制</td><td><a href="https://gitbook.com/docs/documentation/zh/publish/embedding/implementation/nodejs.md">Node.js/NPM</a></td></tr><tr><td><i class="fa-react">:react:</i></td><td><strong>React 组件</strong></td><td>使用预构建的 React 组件实现无缝集成</td><td><a href="https://gitbook.com/docs/documentation/zh/publish/embedding/implementation/react.md">React</a></td></tr></tbody></table>

{% hint style="info" %}
如果你的文档使用了 [身份验证访问](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access.md)，请按照 [如何为经过身份验证的文档设置嵌入](https://gitbook.com/docs/documentation/zh/publish/embedding/using-with-authenticated-docs.md).
{% endhint %}
{% endstep %}

{% step %}
**配置**

* [自定义嵌入](https://gitbook.com/docs/documentation/zh/publish/embedding/configuration/customizing-docs-embed.md) – 添加欢迎消息、自定义操作和建议
* [创建自定义工具](https://gitbook.com/docs/documentation/zh/publish/embedding/configuration/creating-custom-tools.md) – 将助手连接到你的产品 API
  {% endstep %}
  {% endstepper %}

## 延伸阅读

完整的 API 参考和源代码，请参阅 GitHub 上的 [`@gitbook/embed` 软件包](https://github.com/GitbookIO/gitbook/tree/main/packages/embed).


---

# 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/zh/publish/embedding.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.
