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

It's an ongoing effort to create SDK reference docs for all our SDKs, starting with popular SDKs. Here's the current status:

SDKStatus
JavaScript Web SDK✅ Completed
Python SDK✅ Completed
Node.js SDK✅ Completed
React Native SDK✅ Completed
iOS SDK🚧 In progress
Flutter SDK⏳ Not started
Android SDK⏳ Not started
Go SDK⏳ Not started
Java SDK⏳ Not started
Rust SDK⏳ Not started
PHP SDK⏳ Not started
.NET SDK⏳ Not started

How the SDK reference docs work

  1. SDKs are parsed for basic information like class names, method names, and type interfaces.
  2. Descriptions, parameters, return types, and examples are extracted from the SDKs or SDK doc comments.
  3. The information is rewritten into a standardized JSON format (HogRef). They're stored in each SDK's repository under a references directory. For example, the JavaScript Web SDK reference is stored here.
  4. When an SDK releases a new version, the reference docs are generated automatically. Here's an example workflow.
  5. The Strapi instance behind the website is configured to fetch the HogRef JSON files from the SDK's repository and display them on the website via a cron job.
  6. The website renders the HogRef JSON files as a table on the SDK reference page.

Each language works slightly differently, but the general process is the same.

HogRef JSON schema specification

The hierarchy of the HogRef JSON schema is as follows:

Root
├── info (metadata)
├── categories[] (string labels)
├── classes[]
│ ├── functions[]
│ │ ├── params[]
│ │ ├── returnType
│ │ ├── examples[]
│ │ ├── throws[]
│ │ └── overloads[]
│ ├── properties[]
│ ├── staticMethods[]
│ └── events[]
└── types[]
├── properties[]
├── enumValues[]
└── generic[]

Root Object

FieldTypeRequiredDescription
idstringUnique identifier for the SDK (e.g., 'posthog-js', 'stripe-node')
schemaVersionstringVersion of this schema format being used
infoInfoMetadata about the SDK
classesClass[]Main classes/modules exposed by the SDK
typesType[]Type definitions, interfaces, and enums
categoriesstring[]List of functional categories for organizing methods


Info

Metadata about the SDK.

FieldTypeRequiredDescription
idstringPackage/library identifier
titlestringHuman-readable name of the SDK
versionstringCurrent version of the SDK
descriptionstringBrief description of what the SDK does
slugPrefixstringURL-friendly prefix for documentation links
specUrlstring (uri)URL to the source specification or repository
docsUrlstring (uri)URL to the official documentation
licensestringLicense type (e.g., 'MIT', 'Apache-2.0')
platformsstring[]Supported platforms (e.g., 'browser', 'node', 'react-native')


Class

Main classes/modules exposed by the SDK.

FieldTypeRequiredDescription
idstringUnique identifier for the class
titlestringDisplay name of the class
descriptionstringOverview of what this class provides
functionsFunction[]Methods and functions available on this class
propertiesProperty[]Instance properties of this class
staticMethodsFunction[]Static methods on this class
eventsEvent[]Events emitted by this class


Function

Methods and functions available on a class.

FieldTypeRequiredDescription
idstringUnique identifier for the function
titlestringFunction name as it appears in code
descriptionstringBrief description of what the function does
detailsstring | nullExtended explanation, usage notes, or caveats
categorystringFunctional category (e.g., 'Initialization', 'Capture')
releaseTagReleaseTagStability/visibility status of the function
showDocsbooleanWhether to display in public documentation
paramsParameter[]Function parameters
returnTypeTypeReferenceReturn type of the function
examplesExample[]Code examples showing usage
throwsThrowsClause[]Exceptions/errors that may be thrown
sincestringVersion when this function was introduced
deprecatedstring | booleanDeprecation notice or true if deprecated
seeAlsostring[]Related functions or documentation links
pathstringSource file path for this function
asyncbooleanWhether this is an async function
overloadsFunctionOverload[]Alternative function signatures


Parameter

Function parameters.

FieldTypeRequiredDescription
namestringParameter name
typestringType annotation for the parameter
descriptionstringWhat this parameter is for
isOptionalbooleanWhether this parameter is optional
defaultValuestringDefault value if not provided
isRestbooleanWhether this is a rest parameter (...args)


TypeReference

Reference to a type, used for return types and property types.

FieldTypeRequiredDescription
idstringReference ID to a type definition
namestringDisplay name of the type


Type

Type definitions, interfaces, and enums.

FieldTypeRequiredDescription
idstringUnique identifier for this type
namestringType name
descriptionstringWhat this type represents
kindTypeKindKind of type definition
propertiesProperty[]Properties for object types
enumValuesEnumValue[]Values for enum types
examplestringInline type definition or usage example
pathstringSource file path
extendsstring[]Types this type extends
genericGenericParameter[]Generic type parameters


Property

Properties on types or classes.

FieldTypeRequiredDescription
namestringProperty name
typestringType of the property
descriptionstringWhat this property represents
isOptionalbooleanWhether this property is optional
isReadonlybooleanWhether this property is read-only
defaultValuestringDefault value
deprecatedstring | booleanDeprecation notice


Example

Code examples demonstrating usage.

FieldTypeRequiredDescription
idstringUnique identifier for the example
namestringTitle describing what the example demonstrates
codestringThe example code
languagestringProgramming language (e.g., 'javascript', 'typescript')
descriptionstringAdditional explanation of the example


Event

Events emitted by a class.

FieldTypeRequiredDescription
namestringEvent name
descriptionstringWhen this event is emitted
payloadstringType of data passed to event listeners


ThrowsClause

Exceptions/errors that may be thrown by a function.

FieldTypeRequiredDescription
typestringType of error thrown
descriptionstringWhen this error is thrown


EnumValue

Values for enum types.

FieldTypeRequiredDescription
namestringEnum member name
valuestring | numberEnum member value
descriptionstringWhat this enum value represents


GenericParameter

Generic type parameters.

FieldTypeRequiredDescription
namestringGeneric parameter name (e.g., 'T')
constraintstringType constraint (e.g., 'extends string')
defaultstringDefault type


FunctionOverload

Alternative function signatures for overloaded functions.

FieldTypeRequiredDescription
paramsParameter[]Parameters for this overload
returnTypeTypeReferenceReturn type for this overload
descriptionstringDescription specific to this overload


Enumerations

ReleaseTag enum:

ValueDescription
publicStable, public API
betaBeta feature, may change
alphaAlpha feature, likely to change
internalInternal use only
deprecatedDeprecated, avoid use

TypeKind enum:

ValueDescription
interfaceInterface definition
typeType alias
enumEnumeration
classClass definition

Example JSON

JSON
{
"id": "example-sdk",
"schemaVersion": "1.0",
"info": {
"id": "example-sdk",
"title": "Example JavaScript SDK",
"version": "1.0.0",
"description": "Example SDK for tracking events.",
"slugPrefix": "example-sdk",
"specUrl": "https://github.com/example/example-sdk"
},
"categories": ["Capture"],
"classes": [
{
"id": "ExampleClient",
"title": "ExampleClient",
"description": "The main client for tracking events.",
"functions": [
{
"id": "capture",
"title": "capture",
"description": "Captures an event with optional properties.",
"details": "You can capture arbitrary object-like values as events.",
"category": "Capture",
"releaseTag": "public",
"showDocs": true,
"params": [
{
"name": "event_name",
"type": "string",
"description": "The name of the event (e.g., 'Sign Up', 'Button Click')",
"isOptional": false
},
{
"name": "properties",
"type": "Properties | null",
"description": "Properties to include with the event",
"isOptional": true
}
],
"returnType": {
"id": "CaptureResult | undefined",
"name": "CaptureResult | undefined"
},
"examples": [
{
"id": "basic_event_capture",
"name": "basic event capture",
"code": "\n\n// basic event capture\nclient.capture('button-clicked', {\n button_name: 'Get Started',\n page: 'homepage'\n})\n\n"
}
],
"path": "lib/src/client.d.ts"
}
]
}
],
"types": [
{
"id": "Properties",
"name": "Properties",
"properties": [],
"path": "lib/src/types.d.ts",
"example": "{\n $timestamp: '2024-05-29T17:32:07.202Z',\n $os: 'Mac OS X',\n $browser: 'Chrome'\n}"
}
]
}

How to create new SDK reference docs

To contribute a new SDK reference doc:

  1. Create a script to parse the SDK's documentation and extract the information into a HogRef JSON file. The script should:
    • Parse for class names, method names, and type interfaces
    • Extract descriptions, parameters, return types, and examples from the SDK or SDK doc comments
    • Format the information according to the HogRef JSON schema specification
    • Store the HogRef JSON file in a references directory in the SDK's repository
    • See existing SDK repositories for examples, such as the JavaScript Web SDK reference
  2. Create a workflow to generate the HogRef JSON file when a new version of the SDK is released. See an example workflow.
  3. Update the cron-tasks.ts file to fetch the HogRef JSON file from the SDK's repository and display it on the website.
  4. Once the HogRef is ingested into the Strapi instance via the cron job, a new page should be created automatically on the website. The website will render the HogRef JSON file as a table on the SDK reference page.
  5. Find existing links to the SDK's GitHub repository source code and point them to the new HogRef JSON file instead.

Community questions

Was this page useful?

Questions about this page? or post a community question.