> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiIxZDQ3ZTUyOC1lMDQ3LTQ5YmEtYWI4Ni03MWVkMjUxYTgzYjMiLCJleHAiOjE3NzgyNzEwNjMsImlhdCI6MTc3ODI3MDc2M30.3-YdJ6t5Km7meiOrFIC6UBnbBU3Sd4MzaRaunUoud_U
>
> 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.

# Google Analytics

Fern 支持与 [Google Analytics 4](https://developers.google.com/analytics) 和 [Google Tag Manager](https://tagmanager.google.com/) 集成。

## Google Analytics 4

开始之前，请确保您拥有 Google Analytics 4 属性 ID。此 ID 通常采用 `G-XXXXXXXXXX` 格式。

<Steps>
  <Step title="将 GA4 添加到 `docs.yml`">
    打开您的 `docs.yml` 文件，并在 `measurement-id` 键下添加您的 Google Analytics 4 属性 ID：

    <CodeBlock title="docs.yml">
      ```yaml
      analytics:
        ga4:
          measurement-id: G-12345678
      ```
    </CodeBlock>

    您可以选择将 ID 添加为环境变量：

    <CodeBlock title="docs.yml">
      ```yaml
      analytics:
        ga4:
          measurement-id: ${GA4_MEASUREMENT_ID} # 扫描 GA4_MEASUREMENT_ID 环境变量
      ```
    </CodeBlock>
  </Step>

  <Step title="验证您的集成">
    检查浏览器的开发者工具或网络选项卡，确认分析脚本正确加载。请注意，网站流量数据可能需要 24-48 小时才会开始在 Google Analytics 中显示。
  </Step>
</Steps>

## Google Tag Manager

开始之前，请从您的 Google Tag Manager 账户获取容器 ID。此 ID 采用 `GTM-XXXXXX` 格式。

<Steps>
  <Step title="将 GTM 添加到 `docs.yml`">
    打开您的 `docs.yml` 文件，并在 `container-id` 键下添加您的 Google Tag Manager 容器 ID：

    <CodeBlock title="docs.yml">
      ```yaml
      analytics:
        gtm:
          container-id: GTM-NS32L7KR
      ```
    </CodeBlock>

    您可以选择将 ID 添加为环境变量：

    <CodeBlock title="docs.yml">
      ```yaml
      analytics:
        gtm:
          container-id: ${GTM_CONTAINER_ID} # 扫描 GTM_CONTAINER_ID 环境变量
      ```
    </CodeBlock>
  </Step>

  <Step title="验证您的集成">
    检查浏览器的开发者工具或网络选项卡，确认分析脚本正确加载。请注意，网站流量数据可能需要 24-48 小时才会开始在 Google Analytics 中显示。
  </Step>
</Steps>