> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. # PostHog > Learn how to add PostHog analytics to your Fern documentation. Configure your PostHog API key and custom endpoint. Integrate PostHog to track user behavior and analytics in your documentation, including page views, feature usage, and user interactions. #### Get your PostHog API key You can find your PostHog API key under your [project settings](https://us.posthog.com/settings/project). #### Add PostHog to \`docs.yml\` In your `docs.yml` file, add your PostHog configuration: #### docs.yml ```yaml analytics: posthog: api-key: ${POSTHOG_API_KEY} ``` #### Provide the API key at publish time The `${POSTHOG_API_KEY}` syntax reads the key from an environment variable at publish time, so the variable must be present in whatever environment runs `fern generate --docs`. When you publish with a GitHub Actions workflow, map the secret into the publish step's `env`: **`.github/workflows/publish-docs.yml`** ```yaml .github/workflows/publish-docs.yml {4} - name: Publish Docs env: FERN_TOKEN: ${{ secrets.FERN_TOKEN }} POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }} run: | npm install -g fern-api fern generate --docs ``` #### (Optional) Configure a custom endpoint If you use a custom PostHog endpoint, add it to your configuration: #### docs.yml ```yaml {4} analytics: posthog: api-key: ${POSTHOG_API_KEY} endpoint: ${POSTHOG_API_HOST} # e.g. https://analytics.example.com or https://eu.i.posthog.com ``` For a full list of events Fern forwards to your PostHog instance, see the [analytics events reference](/learn/docs/integrations/analytics/events). > Learn how to add PostHog analytics to your Fern documentation. Configure your PostHog API key and custom endpoint.