> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJmNDY2MmUzZi02MWVjLTQ0NWYtYjMzYy00N2Y3ODVlM2U2YjEiLCJleHAiOjE3NzgyNjk5NzYsImlhdCI6MTc3ODI2OTY3Nn0.7LpoD0hVAp3ZGHSjZXZ7mtcpQ9lixRIh9oKMy3GSqvo
>
> 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.

# Segment

> 了解如何在 Fern 文档中添加 Segment 分析。配置 Segment writeKey 的分步指南。

集成 Segment 以收集分析数据并将用户数据路由到您首选的分析目标。

<Steps>
  <Step title="获取您的 Segment writeKey">
    在您的 Segment 工作空间中，导航到您的 Source，然后转到 **Settings > API Keys** 并复制 **Write Key**。
  </Step>

  <Step title="将 Segment 添加到 `docs.yml`">
    在您的 `docs.yml` 文件中，添加 Segment writeKey：

    <CodeBlock title="docs.yml">
      ```yaml
      analytics:
        segment:
          write-key: ${SEGMENT_WRITE_KEY} # scans environment variable
      ```
    </CodeBlock>
  </Step>
</Steps>