Segment

View as Markdown

Integrate Segment to collect analytics and route user data to your preferred analytics destinations.

1

Get your Segment writeKey

In your Segment workspace, navigate to your Source, then go to Settings > API Keys and copy the Write Key.

2

Add Segment to docs.yml

In your docs.yml file, add the Segment writeKey:

docs.yml
1analytics:
2 segment:
3 write-key: ${SEGMENT_WRITE_KEY} # scans environment variable
3

Provide the write key at publish time

The ${SEGMENT_WRITE_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 SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
5 run: |
6 npm install -g fern-api
7 fern generate --docs