SDK reference docs

SDK references document class, method signatures, and type interfaces for each SDK. They complement examples in tutorials and guides by providing a comprehensive reference with all the details. They're important for deep understanding of PostHog SDKs and as context for LLM-based tools. Tutorials and guides reference them for parameter and return type details.

Which SDKs have reference docs

Java, PHP, Ruby, .NET, and the other SDKs don't have a generated reference yet.

How the SDK reference docs work

  1. Each SDK repository generates its reference as Markdown from the SDK's source and doc comments. The files go in the repository's references directory, and their names follow <sdk-id>-<page>.md, where <page> is reference (the newest version), a major version number such as 5, or migration. For example, the React Native files are stored here. In posthog-js, scripts/generate-sdk-reference.mjs writes them.
  2. When an SDK releases a new version, its release workflow regenerates the files. Here's the posthog-js release workflow.
  3. A cron job in the Strapi instance behind the website reads these files from each SDK repository's main branch at 10:00 and 22:00 UTC, and stores each file as one row. See sdkMarkdownReferences in cron-tasks.ts.
  4. At build time, the website writes the rows for the SDKs in PUBLISHED_SDK_REFERENCES (in gatsby/sdkMarkdownReferences.js) to contents/docs/libraries/<sdk>/, and renders them as plain Markdown, never as MDX. The newest version is served at /docs/libraries/<sdk>, each major version at /docs/libraries/<sdk>/<major>.x.x, and the migration guide at /docs/libraries/<sdk>/migration. A production build fails if a published SDK has no rows.

A change to an SDK's reference reaches the website at the first Strapi sync after it merges, followed by a website build.

How to create new SDK reference docs

To add a reference for another SDK:

  1. Write a generator in the SDK's repository that writes <sdk-id>-reference.md, one <sdk-id>-<major>.md per supported major version, and <sdk-id>-migration.md when a major version has breaking changes, to its references directory. Use the generators in existing SDK repositories, such as posthog-js, as examples.
  2. Run the generator in the SDK's release workflow, so the files match each release.
  3. Add the SDK and its references folder to sdkMarkdownReferences in cron-tasks.ts.
  4. After the next Strapi sync, add the SDK to PUBLISHED_SDK_REFERENCES in gatsby/sdkMarkdownReferences.js and to PUBLISHED_SDK_METADATA in src/components/SdkReferences/utils.ts, and link the reference from the docs navigation.

Was this page useful?