PostHog

View as Markdown

Integrate PostHog to track user behavior and analytics in your documentation, including page views, feature usage, and user interactions.

1

Get your PostHog API key

You can find your PostHog API key under your project settings.

2

Add PostHog to docs.yml

In your docs.yml file, add your PostHog configuration:

docs.yml
1analytics:
2 posthog:
3 api-key: ${POSTHOG_API_KEY}
3

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
1- name: Publish Docs
2 env:
3 FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
4 POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
5 run: |
6 npm install -g fern-api
7 fern generate --docs
4

(Optional) Configure a custom endpoint

If you use a custom PostHog endpoint, add it to your configuration:

docs.yml
1analytics:
2 posthog:
3 api-key: ${POSTHOG_API_KEY}
4 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.