Skip to content

Commit f0a91b7

Browse files
committed
chore: Update schema definition docs to include the new languages
1 parent b223ebe commit f0a91b7

File tree

5 files changed

+93
-18
lines changed

5 files changed

+93
-18
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> **Tip:** You can define event schemas with typed properties and generate type-safe code using [schema management](/docs/product-analytics/schema-management).

contents/docs/integrate/send-events/_snippets/send-events-go.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import SettingProperties from "./setting-properties-text.mdx"
2-
import NamingTip from "./naming-tip.mdx"
1+
import SettingProperties from "./setting-properties-text.mdx"
2+
import NamingTip from "./naming-tip.mdx"
3+
import SchemaTip from "./schema-tip.mdx"
34
import Intro from "./intro.mdx"
45

56
<Intro />
@@ -13,6 +14,8 @@ client.Enqueue(posthog.Capture{
1314

1415
<NamingTip />
1516

17+
<SchemaTip />
18+
1619
<SettingProperties />
1720

1821
```go

contents/docs/integrate/send-events/_snippets/send-events-python.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SettingProperties from "./setting-properties-text.mdx"
22
import NamingTip from "./naming-tip.mdx"
3+
import SchemaTip from "./schema-tip.mdx"
34
import Intro from "./intro.mdx"
45

56
<Intro />
@@ -22,6 +23,8 @@ with new_context():
2223

2324
<NamingTip />
2425

26+
<SchemaTip />
27+
2528
<SettingProperties />
2629

2730
```python

contents/docs/integrate/send-events/_snippets/send-events-web.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SettingProperties from "./setting-properties-text.mdx"
22
import NamingTip from "./naming-tip.mdx"
3+
import SchemaTip from "./schema-tip.mdx"
34
import CustomEventIntro from "./intro.mdx"
45

56
By default, PostHog automatically captures pageviews and pageleaves as well as clicks, change of inputs, and form submissions associated with `a`, `button`, `form`, `input`, `select`, `textarea`, and `label` tags. See our [autocapture docs](/docs/product-analytics/autocapture) for more details on this.
@@ -16,6 +17,8 @@ posthog.capture('user_signed_up');
1617

1718
<NamingTip />
1819

20+
<SchemaTip />
21+
1922
<SettingProperties />
2023

2124
```js-web

contents/docs/product-analytics/schema-management.mdx

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Schema management lets you define and enforce the structure of your events using
1717
You can create event definitions before any events are actually captured. This is useful when planning your analytics implementation upfront, allowing you to:
1818

1919
- Define your event schema before writing instrumentation code
20-
- Generate TypeScript types for events that haven't been captured yet
20+
- Generate typed definitions for events that haven't been captured yet
2121
- Document expected events for your team
2222
- Ensure consistency across your codebase from day one
2323

@@ -88,13 +88,7 @@ Events can have multiple property groups, and each group's properties will be in
8888

8989
## Downloading your schema with the CLI
9090

91-
The PostHog CLI generates TypeScript definitions from your configured schemas.
92-
93-
<CalloutBox icon="IconInfo" title="TypeScript support" type="fyi">
94-
95-
TypeScript is currently the only supported language for schema generation.
96-
97-
</CalloutBox>
91+
The PostHog CLI generates language definitions from your configured schemas.
9892

9993
### Install the CLI
10094

@@ -114,19 +108,21 @@ This opens your browser to authorize the CLI with your PostHog account.
114108

115109
### Download your schema
116110

111+
> **Note:** Schema management is currently an experimental feature. The `exp` prefix will be removed once the feature is stable.
112+
117113
```bash
118114
posthog-cli exp schema pull
119115
```
120116

121117
The CLI will:
122118
1. Fetch your event schemas
123-
2. Generate TypeScript definitions
124-
3. Save them to a file (default: `posthog-typed.ts`)
119+
2. Prompt you for the output file path
120+
3. Generate typed definitions and save them to the specified file
125121
4. Update `posthog.json` with the schema hash
126122

127-
When prompted for the output path, choose a location that's accessible from your application code (e.g., `src/lib/posthog-typed.ts` or `app/lib/posthog-typed.ts`).
123+
When prompted for the output path, choose a location that's accessible from your application code (e.g., `src/lib/posthog-typed.ts` or `app/lib/posthog-typed.ts` for TypeScript).
128124

129-
**Important:** Commit both `posthog.json` and `posthog-typed.ts` to your git repository. This ensures your team has consistent types and tracks schema changes over time.
125+
**Important:** Commit both `posthog.json` and `posthog-typed.<extension>` to your git repository. This ensures your team has consistent types and tracks schema changes over time.
130126

131127
On subsequent runs, the CLI only updates the file if your schema has changed.
132128

@@ -142,7 +138,11 @@ This shows your current sync status, including the schema hash, last updated tim
142138

143139
Once you've downloaded your schema, import and use the generated PostHog client:
144140

145-
```typescript
141+
142+
<MultiLanguage selector="tabs">
143+
144+
```typescript file=TypeScript
145+
146146
import posthog from './posthog-typed'
147147

148148
// Use typed events with autocomplete and type safety on known events:
@@ -156,11 +156,76 @@ posthog.capture('button_clicked', {
156156
posthog.captureRaw('dynamic_event', { whatever: 'data' })
157157
```
158158

159-
The generated client provides:
159+
```go file=Go
160+
161+
import (
162+
"github.com/posthog/posthog-go"
163+
typed "your-project/posthog-typed"
164+
)
165+
166+
func captureEventWithRequiredProperties(client posthog.Client) error {
167+
return client.Enqueue(typed.DashboardModeToggledCapture("distinct_id", 2048,
168+
typed.DashboardModeToggledWithFileName("file_name"),
169+
typed.DashboardModeToggledWithFileType(".pdf"),
170+
typed.DashboardModeToggledWithExtraProps(posthog.Properties{
171+
"extra": "property",
172+
}),
173+
))
174+
}
175+
176+
func captureEventWithNoRequiredProperties(client posthog.Client) error {
177+
return client.Enqueue(typed.DashboardLoadingTimeCapture("distinct_id", posthog.Properties{
178+
"test": "property",
179+
"two_and_two_is": 4,
180+
}))
181+
}
182+
183+
func captureEventWithFullCaptureControl(client posthog.Client) error {
184+
return client.Enqueue(typed.DashboardLoadingTimeCaptureFromBase(
185+
// Event should be omitted here as it will be retrieved from the typed function.
186+
posthog.Capture{
187+
DistinctId: "distinct_id",
188+
Timestamp: time.Now(),
189+
// ... Any additional properties
190+
},
191+
posthog.Properties{
192+
"test": "property",
193+
},
194+
))
195+
}
196+
197+
```
198+
199+
```python file=Python
200+
201+
import os
202+
203+
from posthog_typed import PosthogTyped
204+
205+
def main():
206+
posthog = PosthogTyped(
207+
POSTHOG_API_KEY,
208+
host=POSTHOG_HOST,
209+
)
210+
211+
# Base captures are still possible as well
212+
posthog.capture("capture_raw_example", distinct_id="distinct_id", properties={"test": "property"})
213+
# Capture with required properties
214+
posthog.capture_downloaded_file(file_size_b=2048, file_name="file_name", distinct_id="distinct_id",
215+
extra_properties={"test": "property"})
216+
# Capture with no required properties
217+
posthog.capture_user_logged_in(extra_properties={"test": "property"}, distinct_id="distinct_id")
218+
219+
```
220+
221+
</MultiLanguage>
222+
223+
224+
The generated typed file provides:
160225
- **Type safety**: Properties are validated against your schema
161226
- **Autocomplete**: Your IDE suggests event names and properties
162227
- **Documentation**: Inline types show required properties and descriptions
163-
- **Flexibility**: `capture()` remains available for dynamic events
228+
- **Flexibility**: The standard SDK functionality remains available, allowing gradual migrations
164229

165230
![TypeScript type checking in action](https://res.cloudinary.com/dmukukwp6/image/upload/w_1600,c_limit,q_auto,f_auto/typescript_type_checking_a5318b2d7e.png)
166231

@@ -170,4 +235,4 @@ The generated client provides:
170235
- **Start with your most important events**: Define schemas for critical conversion events first
171236
- **Use descriptive property groups**: Name groups by their purpose (e.g., "E-commerce Properties", "User Context")
172237
- **Don't over-schema**: Not every event needs a schema—use them where type safety adds value
173-
- **Commit generated types**: Always commit `posthog-typed.ts` and `posthog.json` to version control so your team stays in sync
238+
- **Commit generated types**: Always commit `posthog.json` and `posthog-typed.<extension>` to version control so your team stays in sync

0 commit comments

Comments
 (0)