Skip to navigation

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
analytics:
posthog:
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
- 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
4

(Optional) Configure a custom endpoint

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

docs.yml
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.