> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI4YmZkZmMwMi1hZTkyLTRmOGEtYmJkYy05MDhiY2M5ZWNiYzkiLCJleHAiOjE3NzgyNzA2MDAsImlhdCI6MTc3ODI3MDMwMH0.sPj2oC5kcgSEKgs-OHAU9ITsN-i8M1iFvMkMogDNOdY
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 分析和集成

> 将分析和支持工具连接到您的 Fern 文档。设置 PostHog、Segment、FullStory、Intercom 和 Postman 集合。

<CardGroup cols={2}>
  <Card title="PostHog" href="/docs/integrations/analytics/posthog" horizontal icon={<img src="https://cdn.brandfetch.io/id2veLU_gI/idG9S94wXO.svg" />} iconSize={12} />

  <Card
    title="Segment"
    href="/docs/integrations/analytics/segment"
    horizontal
    icon={
    <img src="https://cdn.brandfetch.io/idiousYjQz/theme/dark/symbol.svg?k=id64Mup7ac&t=1717151164256?t=1717151164256" />
  }
    iconSize={12}
  />

  <Card title="FullStory" href="/docs/integrations/analytics/fullstory" horizontal icon={<img src="https://cdn.brandfetch.io/idRtIBDum6/w/400/h/400/theme/dark/icon.jpeg" />} iconSize={12} />

  <Card title="Intercom" href="/docs/integrations/support/intercom" horizontal icon={<img src="https://cdn.brandfetch.io/idYJNDWF1m/theme/dark/symbol.svg" />} iconSize={12} />

  <Card title="Postman" href="/docs/integrations/postman" horizontal icon={<img src="https://www.svgrepo.com/show/354202/postman-icon.svg" />} iconSize={12} />

  <Card title="Context7" href="/docs/integrations/context7" horizontal icon={<img src="https://context7.com/favicon.ico" />} iconSize={12} />
</CardGroup>

## 启用分析

您可以在 `docs.yml` 中定义分析配置。只需为您要连接的平台添加相应条目。

```yaml docs.yml
analytics:
  posthog:
    api-key: ${POSTHOG_API_KEY}
    endpoint: https://self.hosted.posthog.com/
  segment:
    write-key: ${SEGMENT_WRITE_KEY}
  intercom:
    app-id: ${INTERCOM_APP_ID}
    endpoint: https://intercom.custom-instance.com/
  fullstory:
    org-id: ${FULLSTORY_ORG_ID}
```

### 环境变量

如果您的文档配置是公开的，请不要直接将密钥值写入 `docs.yml`。
请使用 `${VARIABLE_NAME}` 语法引用环境变量。

<Note>
  如果您使用 GitHub Workflows 触发文档生成，请确保这些环境变量在工作流运行时可用。

  ```yaml {4}
  - name: Publish Docs
    env:
      FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
      POSTHOG_API_KEY: ${{ secrets.POSTHOG_PROJECT_API_KEY }}
    run: |
      npm install -g fern-api
      fern generate --docs
  ```
</Note>

## 通过自定义 JavaScript 连接其他集成

<Warning title="企业功能">
  此功能仅适用于[企业计划](https://buildwithfern.com/pricing)。如需开始使用，请联系 [support@buildwithfern.com](mailto:support@buildwithfern.com)。
</Warning>

对于 Fern 在 `docs.yml` 中没有原生支持的第三方工具，只要它们支持基于 HTML 标签的安装方式，您都可以通过 [自定义 JavaScript](/docs/customization/custom-css-js#custom-javascript) 进行集成。这适用于以下工具：

* **分析：** Amplitude、Heap、Plausible
* **会话录制：** Hotjar、LogRocket、Microsoft Clarity
* **支持和聊天：** Zendesk、Crisp、Drift
* **标签管理器：** Adobe Launch、Tealium

将供应商的 `<script>` 代码片段粘贴到自定义 JS 文件中，并在 `docs.yml` 中引用：

<CodeBlock title="docs.yml">
  ```yaml
  js: ./custom.js
  ```
</CodeBlock>