vybekiit 0.7.33 → 0.7.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/bin.js +818 -92
  2. package/dist/global-skills/eas-app-stores/SKILL.md +2 -2
  3. package/dist/global-skills/eas-hosting/SKILL.md +2 -2
  4. package/dist/global-skills/eas-observe/SKILL.md +7 -15
  5. package/dist/global-skills/eas-observe/references/queries.md +51 -10
  6. package/dist/global-skills/eas-observe/references/setup.md +60 -7
  7. package/dist/global-skills/eas-simulator/SKILL.md +2 -2
  8. package/dist/global-skills/eas-simulator/references/run-your-app.md +2 -0
  9. package/dist/global-skills/eas-update/SKILL.md +2 -2
  10. package/dist/global-skills/eas-update-insights/SKILL.md +2 -2
  11. package/dist/global-skills/eas-workflows/SKILL.md +2 -2
  12. package/dist/global-skills/expo-animation/SKILL.md +2 -2
  13. package/dist/global-skills/expo-app-clip/SKILL.md +2 -2
  14. package/dist/global-skills/expo-brownfield/SKILL.md +2 -2
  15. package/dist/global-skills/expo-data-fetching/SKILL.md +2 -2
  16. package/dist/global-skills/expo-design-system/SKILL.md +2 -2
  17. package/dist/global-skills/expo-dev-client/SKILL.md +4 -2
  18. package/dist/global-skills/expo-dom/SKILL.md +2 -2
  19. package/dist/global-skills/expo-examples/SKILL.md +2 -2
  20. package/dist/global-skills/expo-migrate-module/SKILL.md +2 -2
  21. package/dist/global-skills/expo-module/SKILL.md +2 -2
  22. package/dist/global-skills/expo-native-ui/SKILL.md +2 -2
  23. package/dist/global-skills/expo-overview/SKILL.md +9 -4
  24. package/dist/global-skills/expo-overview/references/launch-without-dev-menu.md +24 -0
  25. package/dist/global-skills/expo-project-structure/SKILL.md +2 -2
  26. package/dist/global-skills/expo-router/SKILL.md +2 -2
  27. package/dist/global-skills/expo-ui/SKILL.md +2 -2
  28. package/dist/global-skills/expo-upgrade/SKILL.md +2 -2
  29. package/dist/global-skills/expo-web-to-native/SKILL.md +2 -2
  30. package/dist/global-skills/expo-web-to-native/references/verify-on-device.md +1 -1
  31. package/dist/global-skills/firebase-app-hosting-basics/SKILL.md +16 -3
  32. package/dist/global-skills/firebase-app-hosting-basics/references/cli_commands.md +10 -12
  33. package/dist/global-skills/firebase-app-hosting-basics/references/configuration.md +2 -1
  34. package/dist/global-skills/firebase-basics/SKILL.md +6 -4
  35. package/dist/global-skills/firebase-basics/references/web_setup.md +3 -3
  36. package/dist/global-skills/instrument-feature-flags/references/adding-feature-flag-code.md +81 -333
  37. package/dist/global-skills/instrument-feature-flags/references/android.md +19 -13
  38. package/dist/global-skills/instrument-feature-flags/references/api.md +17 -13
  39. package/dist/global-skills/instrument-feature-flags/references/best-practices.md +35 -35
  40. package/dist/global-skills/instrument-feature-flags/references/django.md +120 -72
  41. package/dist/global-skills/instrument-feature-flags/references/dotnet.md +48 -102
  42. package/dist/global-skills/instrument-feature-flags/references/elixir.md +4 -10
  43. package/dist/global-skills/instrument-feature-flags/references/flask.md +55 -39
  44. package/dist/global-skills/instrument-feature-flags/references/flutter.md +19 -13
  45. package/dist/global-skills/instrument-feature-flags/references/go.md +21 -13
  46. package/dist/global-skills/instrument-feature-flags/references/ios.md +19 -13
  47. package/dist/global-skills/instrument-feature-flags/references/java.md +4 -12
  48. package/dist/global-skills/instrument-feature-flags/references/laravel.md +18 -16
  49. package/dist/global-skills/instrument-feature-flags/references/next-js.md +44 -54
  50. package/dist/global-skills/instrument-feature-flags/references/nodejs.md +21 -13
  51. package/dist/global-skills/instrument-feature-flags/references/php.md +21 -13
  52. package/dist/global-skills/instrument-feature-flags/references/python.md +22 -14
  53. package/dist/global-skills/instrument-feature-flags/references/react-native.md +18 -13
  54. package/dist/global-skills/instrument-feature-flags/references/react.md +21 -14
  55. package/dist/global-skills/instrument-feature-flags/references/ruby-on-rails.md +31 -68
  56. package/dist/global-skills/instrument-feature-flags/references/ruby.md +21 -13
  57. package/dist/global-skills/instrument-feature-flags/references/rust.md +10 -34
  58. package/dist/global-skills/instrument-feature-flags/references/usage.md +94 -114
  59. package/dist/global-skills/instrument-feature-flags/references/web.md +21 -13
  60. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-android.md +7 -7
  61. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-expo.md +2 -2
  62. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-fastapi.md +1 -1
  63. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-flask.md +1 -1
  64. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-laravel.md +2 -2
  65. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-php.md +1 -1
  66. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-python.md +1 -1
  67. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-ruby.md +1 -1
  68. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-swift.md +4 -4
  69. package/dist/global-skills/instrument-product-analytics/references/android.md +64 -109
  70. package/dist/global-skills/instrument-product-analytics/references/angular.md +32 -28
  71. package/dist/global-skills/instrument-product-analytics/references/astro.md +29 -34
  72. package/dist/global-skills/instrument-product-analytics/references/configuration.md +27 -42
  73. package/dist/global-skills/instrument-product-analytics/references/django.md +120 -72
  74. package/dist/global-skills/instrument-product-analytics/references/dotnet.md +48 -102
  75. package/dist/global-skills/instrument-product-analytics/references/elixir.md +25 -50
  76. package/dist/global-skills/instrument-product-analytics/references/flask.md +55 -39
  77. package/dist/global-skills/instrument-product-analytics/references/flutter.md +94 -96
  78. package/dist/global-skills/instrument-product-analytics/references/go.md +39 -77
  79. package/dist/global-skills/instrument-product-analytics/references/identify-users.md +24 -26
  80. package/dist/global-skills/instrument-product-analytics/references/ios.md +22 -22
  81. package/dist/global-skills/instrument-product-analytics/references/laravel.md +18 -16
  82. package/dist/global-skills/instrument-product-analytics/references/next-js.md +44 -54
  83. package/dist/global-skills/instrument-product-analytics/references/nuxt-js-3-6.md +32 -34
  84. package/dist/global-skills/instrument-product-analytics/references/nuxt-js.md +36 -36
  85. package/dist/global-skills/instrument-product-analytics/references/php.md +42 -87
  86. package/dist/global-skills/instrument-product-analytics/references/posthog-python.md +15 -12
  87. package/dist/global-skills/instrument-product-analytics/references/python.md +106 -154
  88. package/dist/global-skills/instrument-product-analytics/references/react-native.md +97 -176
  89. package/dist/global-skills/instrument-product-analytics/references/react-router-v6.md +29 -40
  90. package/dist/global-skills/instrument-product-analytics/references/react-router-v7-data-mode.md +29 -38
  91. package/dist/global-skills/instrument-product-analytics/references/react-router-v7-declarative-mode.md +29 -40
  92. package/dist/global-skills/instrument-product-analytics/references/react-router-v7-framework-mode.md +32 -37
  93. package/dist/global-skills/instrument-product-analytics/references/ruby-on-rails.md +31 -68
  94. package/dist/global-skills/instrument-product-analytics/references/ruby.md +40 -96
  95. package/dist/global-skills/instrument-product-analytics/references/svelte.md +34 -34
  96. package/dist/global-skills/instrument-product-analytics/references/tanstack-start.md +19 -19
  97. package/dist/global-skills/instrument-product-analytics/references/usage.md +94 -114
  98. package/dist/global-skills/instrument-product-analytics/references/vue-js.md +33 -45
  99. package/dist/global-skills/manifest.json +2 -1
  100. package/dist/global-skills/mongodb-search-and-ai/SKILL.md +40 -22
  101. package/dist/global-skills/mongodb-search-and-ai/references/automated-embedding.md +8 -2
  102. package/dist/global-skills/mongodb-search-and-ai/references/quick-start.md +725 -0
  103. package/dist/global-skills/mongodb-search-and-ai/scripts/quickstart_complete.py +386 -0
  104. package/dist/global-skills/neon/SKILL.md +15 -10
  105. package/dist/global-skills/neon/references/claimable-neon.md +2 -0
  106. package/dist/global-skills/neon-functions/SKILL.md +12 -11
  107. package/dist/global-skills/neon-functions/references/sse.md +2 -2
  108. package/dist/global-skills/neon-object-storage/SKILL.md +5 -4
  109. package/dist/global-skills/neon-postgres/SKILL.md +4 -1
  110. package/dist/global-skills/neon-realtime/SKILL.md +207 -0
  111. package/dist/global-skills/neon-realtime/references/mutations.md +743 -0
  112. package/dist/global-skills/neon-realtime/references/queries.md +509 -0
  113. package/dist/global-skills/neon-realtime/references/reactivity.md +407 -0
  114. package/dist/global-skills/neon-realtime/references/ssr.md +695 -0
  115. package/dist/global-skills/neon-realtime/references/subscribing.md +485 -0
  116. package/dist/global-skills/resend/SKILL.md +4 -2
  117. package/dist/global-skills/resend/references/inboxes.md +377 -0
  118. package/dist/global-skills/resend/references/webhooks.md +9 -0
  119. package/dist/global-skills/stripe-best-practices/SKILL.md +1 -1
  120. package/dist/global-skills/stripe-best-practices/references/connect.md +1 -1
  121. package/dist/global-skills/stripe-best-practices/references/security.md +9 -9
  122. package/dist/global-skills/vybekiitReferences/backend/AGENTS.md +1 -1
  123. package/dist/global-skills/vybekiitReferences/backend/agent/goal-routes.json +303 -18
  124. package/dist/global-skills/vybekiitReferences/extension/AGENTS.md +1 -1
  125. package/dist/global-skills/vybekiitReferences/extension/agent/goal-routes.json +352 -18
  126. package/dist/global-skills/vybekiitReferences/mobile/AGENTS.md +1 -1
  127. package/dist/global-skills/vybekiitReferences/mobile/agent/goal-routes.json +413 -22
  128. package/dist/global-skills/vybekiitReferences/spa/AGENTS.md +1 -1
  129. package/dist/global-skills/vybekiitReferences/spa/agent/goal-routes.json +391 -21
  130. package/dist/global-skills/vybekiitReferences/web/AGENTS.md +14 -2
  131. package/dist/global-skills/vybekiitReferences/web/agent/goal-routes.json +490 -32
  132. package/package.json +8 -8
@@ -2,22 +2,37 @@
2
2
 
3
3
  # PHP
4
4
 
5
+ Canonical URL: https://posthog.com/docs/libraries/php
6
+
7
+ > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.i.posthog.com` instead of `https://us.i.posthog.com` (ingestion host), and use `https://eu.posthog.com` instead of `https://app.posthog.com` (app host for links).
8
+
9
+ ## On this page
10
+
11
+ - [Installation](#installation)
12
+ - [Identifying users](#identifying-users)
13
+ - [Capturing events](#capturing-events)
14
+ - [Person profiles and properties](#person-profiles-and-properties)
15
+ - [Alias](#alias)
16
+ - [Feature flags](#feature-flags)
17
+ - [Request context](#request-context)
18
+ - [Error tracking](#error-tracking)
19
+ - [Config options](#config-options)
20
+ - [Flushing and shutting down](#flushing-and-shutting-down)
21
+ - [Debug mode](#debug-mode)
22
+ - [Thank you](#thank-you)
23
+
5
24
  This is an optional library you can install if you're working with PHP. It uses an internal queue to batch requests, flushes at the end of the request, and optionally does so in an async manner.
6
25
 
7
26
  ## Installation
8
27
 
9
28
  Install the package with Composer:
10
29
 
11
- Terminal
12
-
13
30
  ```bash
14
31
  composer require posthog/posthog-php
15
32
  ```
16
33
 
17
34
  In your app, set your project token before making any calls.
18
35
 
19
- PHP
20
-
21
36
  ```php
22
37
  PostHog\PostHog::init("<ph_project_token>",
23
38
  ['host' => 'https://us.i.posthog.com']
@@ -30,16 +45,14 @@ You can find your project token and instance address in the [project settings](h
30
45
 
31
46
  ## Identifying users
32
47
 
33
- > **Identifying users is required.** Backend events need a `distinct_id` that matches the ID your frontend uses when calling `posthog.identify()`. Without this, backend events are orphaned — they can't be linked to frontend event captures, [session replays](/docs/session-replay.md), [LLM traces](/docs/ai-engineering.md), or [error tracking](/docs/error-tracking.md).
48
+ > **Identifying users is required.** Backend events need a `distinct_id` that matches the ID your frontend uses when calling `posthog.identify()`. Without this, backend events are orphaned — they can't be linked to frontend event captures, [session replays](https://posthog.com/docs/session-replay.md), [LLM traces](https://posthog.com/docs/ai-engineering.md), or [error tracking](https://posthog.com/docs/error-tracking.md).
34
49
  >
35
- > See our guide on [identifying users](/docs/getting-started/identify-users.md) for how to set this up.
50
+ > See our guide on [identifying users](https://posthog.com/docs/getting-started/identify-users.md) for how to set this up.
36
51
 
37
52
  ## Capturing events
38
53
 
39
54
  You can send custom events using `capture`:
40
55
 
41
- PHP
42
-
43
56
  ```php
44
57
  PostHog::capture([
45
58
  'distinctId' => 'distinct_id_of_the_user',
@@ -51,9 +64,7 @@ PostHog::capture([
51
64
 
52
65
  ### Setting event properties
53
66
 
54
- Optionally, you can include additional information with the event by including a [properties](/docs/data/events.md#event-properties) object:
55
-
56
- PHP
67
+ Optionally, you can include additional information with the event by including a [properties](https://posthog.com/docs/data/events.md#event-properties) object:
57
68
 
58
69
  ```php
59
70
  PostHog::capture([
@@ -70,8 +81,6 @@ PostHog::capture([
70
81
 
71
82
  If you're aiming for a backend-only implementation of PostHog and won't be capturing events from your frontend, you can send `pageviews` from your backend like so:
72
83
 
73
- PHP
74
-
75
84
  ```php
76
85
  PostHog::capture([
77
86
  'distinctId' => 'distinct_id_of_the_user',
@@ -84,9 +93,7 @@ PostHog::capture([
84
93
 
85
94
  ## Person profiles and properties
86
95
 
87
- The PHP SDK captures identified events by default. These create [person profiles](/docs/data/persons.md). To set [person properties](/docs/product-analytics/person-properties.md), call `identify` with the user's distinct ID and properties:
88
-
89
- PHP
96
+ The PHP SDK captures identified events by default. These create [person profiles](https://posthog.com/docs/data/persons.md). To set [person properties](https://posthog.com/docs/product-analytics/person-properties.md), call `identify` with the user's distinct ID and properties:
90
97
 
91
98
  ```php
92
99
  PostHog::identify([
@@ -100,8 +107,6 @@ PostHog::identify([
100
107
 
101
108
  You can also include person properties when capturing an event:
102
109
 
103
- PHP
104
-
105
110
  ```php
106
111
  PostHog::capture([
107
112
  'distinctId' => 'distinct_id',
@@ -117,11 +122,9 @@ PostHog::capture([
117
122
  ]);
118
123
  ```
119
124
 
120
- For more details on the difference between `$set` and `$set_once`, see our [person properties docs](/docs/product-analytics/person-properties.md#what-is-the-difference-between-set-and-set_once).
121
-
122
- To capture [anonymous events](/docs/data/anonymous-vs-identified-events.md) without person profiles, set the event's `$process_person_profile` property to `false`:
125
+ For more details on the difference between `$set` and `$set_once`, see our [person properties docs](https://posthog.com/docs/product-analytics/person-properties.md#what-is-the-difference-between-set-and-set_once).
123
126
 
124
- PHP
127
+ To capture [anonymous events](https://posthog.com/docs/data/anonymous-vs-identified-events.md) without person profiles, set the event's `$process_person_profile` property to `false`:
125
128
 
126
129
  ```php
127
130
  PostHog::capture([
@@ -139,8 +142,6 @@ Sometimes, you want to assign multiple distinct IDs to a single user. This is he
139
142
 
140
143
  In this case, you can use `alias` to assign another distinct ID to the same user.
141
144
 
142
- PHP
143
-
144
145
  ```php
145
146
  PostHog::alias([
146
147
  'distinctId' => 'distinct_id',
@@ -148,11 +149,11 @@ PostHog::alias([
148
149
  ]);
149
150
  ```
150
151
 
151
- We strongly recommend reading our docs on [alias](/docs/product-analytics/identify.md#alias-assigning-multiple-distinct-ids-to-the-same-user) to best understand how to correctly use this method.
152
+ We strongly recommend reading our docs on [alias](https://posthog.com/docs/product-analytics/identify.md#alias-assigning-multiple-distinct-ids-to-the-same-user) to best understand how to correctly use this method.
152
153
 
153
154
  ## Feature flags
154
155
 
155
- PostHog's [feature flags](/docs/feature-flags.md) enable you to safely deploy and roll back new features as well as target specific users and groups with them.
156
+ PostHog's [feature flags](https://posthog.com/docs/feature-flags.md) enable you to safely deploy and roll back new features as well as target specific users and groups with them.
156
157
 
157
158
  There are two steps to implement feature flags in PHP:
158
159
 
@@ -162,8 +163,6 @@ Call `PostHog::evaluateFlags()` once for the user, then read values from the ret
162
163
 
163
164
  #### Boolean feature flags
164
165
 
165
- PHP
166
-
167
166
  ```php
168
167
  $flags = PostHog::evaluateFlags('distinct_id_of_your_user');
169
168
 
@@ -176,8 +175,6 @@ if ($flags->isEnabled('flag-key')) {
176
175
 
177
176
  #### Multivariate feature flags
178
177
 
179
- PHP
180
-
181
178
  ```php
182
179
  $flags = PostHog::evaluateFlags('distinct_id_of_your_user');
183
180
 
@@ -198,9 +195,9 @@ You can also call `$flags->getKeys()` to list the evaluated flag keys, or `$flag
198
195
 
199
196
  ### Step 2: Include feature flag information when capturing events
200
197
 
201
- If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
198
+ If you want use your feature flag to breakdown or filter events in your [insights](https://posthog.com/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
202
199
 
203
- > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
200
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](https://posthog.com/docs/api.md).
204
201
 
205
202
  There are two methods you can use to include feature flag information in your events:
206
203
 
@@ -208,8 +205,6 @@ There are two methods you can use to include feature flag information in your ev
208
205
 
209
206
  Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
210
207
 
211
- PHP
212
-
213
208
  ```php
214
209
  $flags = PostHog::evaluateFlags('distinct_id_of_your_user');
215
210
 
@@ -228,8 +223,6 @@ By default, this attaches every flag in the snapshot using `$feature/<flag-key>`
228
223
 
229
224
  To reduce event property bloat, pass a filtered snapshot:
230
225
 
231
- PHP
232
-
233
226
  ```php
234
227
  // Attach only flags accessed with isEnabled() or getFlag() before this call
235
228
  PostHog::capture([
@@ -252,8 +245,6 @@ PostHog::capture([
252
245
 
253
246
  In the event properties, include `$feature/feature_flag_name: variant_key`:
254
247
 
255
- PHP
256
-
257
248
  ```php
258
249
  PostHog::capture([
259
250
  'distinctId' => 'distinct_id_of_your_user',
@@ -269,8 +260,6 @@ PostHog::capture([
269
260
 
270
261
  By default, `evaluateFlags()` evaluates every flag for the user. If you only need a few flags, pass `flagKeys` to request only those flags:
271
262
 
272
- PHP
273
-
274
263
  ```php
275
264
  $flags = PostHog::evaluateFlags(
276
265
  distinctId: 'distinct_id_of_your_user',
@@ -282,8 +271,6 @@ $flags = PostHog::evaluateFlags(
282
271
 
283
272
  `evaluateFlags()` also accepts optional parameters for local evaluation and GeoIP behavior:
284
273
 
285
- PHP
286
-
287
274
  ```php
288
275
  $flags = PostHog::evaluateFlags(
289
276
  distinctId: 'distinct_id_of_your_user',
@@ -298,7 +285,7 @@ $flags = PostHog::evaluateFlags(
298
285
 
299
286
  ### Sending `$feature_flag_called` events
300
287
 
301
- Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluateFlags()`, the SDK sends this event when you call `$flags->isEnabled()` or `$flags->getFlag()` for a flag.
288
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](https://posthog.com/docs/product-analytics/insights.md) on the flag. With `evaluateFlags()`, the SDK sends this event when you call `$flags->isEnabled()` or `$flags->getFlag()` for a flag.
302
289
 
303
290
  The SDK deduplicates these events per `(flag key, distinct_id)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
304
291
 
@@ -306,14 +293,12 @@ The SDK deduplicates these events per `(flag key, distinct_id)` in a local cache
306
293
 
307
294
  ### Advanced: Overriding server properties
308
295
 
309
- Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
296
+ Sometimes, you may want to evaluate feature flags using [person properties](https://posthog.com/docs/product-analytics/person-properties.md), [groups](https://posthog.com/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
310
297
 
311
298
  You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
312
299
 
313
300
  For example:
314
301
 
315
- PHP
316
-
317
302
  ```php
318
303
  $flags = PostHog::evaluateFlags(
319
304
  distinctId: 'distinct_id_of_the_user',
@@ -364,8 +349,6 @@ Simply include any of these properties in the `person_properties` parameter alon
364
349
 
365
350
  You can configure the `feature_flag_request_timeout_ms` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked if PostHog's servers are too slow to respond. By default, this is set to 3 seconds.
366
351
 
367
- PHP
368
-
369
352
  ```php
370
353
  PostHog::init("<ph_project_token>",
371
354
  [
@@ -381,25 +364,21 @@ Evaluating feature flags requires making a request to PostHog for each flag. How
381
364
 
382
365
  It is best practice to use local evaluation flags when possible, since this enables you to resolve flags faster and with fewer API calls.
383
366
 
384
- To load feature flag definitions for local evaluation, initialize the SDK with your feature flags secure API key as `personalAPIKey`:
385
-
386
- PHP
367
+ To load feature flag definitions for local evaluation, initialize the SDK with your secret API key as `personalAPIKey`:
387
368
 
388
369
  ```php
389
370
  PostHog::init(
390
371
  '<ph_project_token>',
391
372
  ['host' => 'https://us.i.posthog.com'],
392
- personalAPIKey: 'your feature flags secure API key'
373
+ personalAPIKey: 'your secret API key'
393
374
  );
394
375
  ```
395
376
 
396
- For details on how to implement local evaluation, see our [local evaluation guide](/docs/feature-flags/local-evaluation.md). For distributed or stateless PHP applications, use `flag_definition_cache_provider` to share flag definitions across workers or requests. See [local evaluation in distributed environments](/docs/feature-flags/local-evaluation/distributed-environments?tab=PHP.md).
377
+ For details on how to implement local evaluation, see our [local evaluation guide](https://posthog.com/docs/feature-flags/local-evaluation.md). For distributed or stateless PHP applications, use `flag_definition_cache_provider` to share flag definitions across workers or requests. See [local evaluation in distributed environments](https://posthog.com/docs/feature-flags/local-evaluation/distributed-environments?tab=PHP.md).
397
378
 
398
379
  ### Experiments (A/B tests)
399
380
 
400
- Since [experiments](/docs/experiments/start-here.md) use feature flags, the code for running an experiment is very similar to the feature flags code:
401
-
402
- PHP
381
+ Since [experiments](https://posthog.com/docs/experiments/start-here.md) use feature flags, the code for running an experiment is very similar to the feature flags code:
403
382
 
404
383
  ```php
405
384
  $flags = PostHog::evaluateFlags('user_distinct_id');
@@ -410,18 +389,16 @@ if ($variant === 'variant-name') {
410
389
  }
411
390
  ```
412
391
 
413
- It's also possible to [run experiments without using feature flags](/docs/experiments/running-experiments-without-feature-flags.md).
392
+ It's also possible to [run experiments without using feature flags](https://posthog.com/docs/experiments/running-experiments-without-feature-flags.md).
414
393
 
415
394
  ### Group analytics
416
395
 
417
- Group analytics allows you to associate an event with a group (e.g. teams, organizations, etc.). This feature requires version `2.1.0` or above of the PHP SDK. Read the [group analytics guide](/docs/product-analytics/group-analytics.md) for more information.
396
+ Group analytics allows you to associate an event with a group (e.g. teams, organizations, etc.). This feature requires version `2.1.0` or above of the PHP SDK. Read the [group analytics guide](https://posthog.com/docs/product-analytics/group-analytics.md) for more information.
418
397
 
419
- > **Note:** This is a paid feature and is not available on the open-source or free cloud plan. Learn more on the [pricing page](/pricing.md).
398
+ > **Note:** This is a paid feature and is not available on the open-source or free cloud plan. Learn more on the [pricing page](https://posthog.com/pricing.md).
420
399
 
421
400
  To create a group or update its properties, use `groupIdentify`:
422
401
 
423
- PHP
424
-
425
402
  ```php
426
403
  PostHog::groupIdentify([
427
404
  'groupType' => 'company',
@@ -442,8 +419,6 @@ If the optional `distinctId` parameter is not provided in the group identify cal
442
419
 
443
420
  Once a group is created, you can use the `capture` method and pass in the `groups` parameter to capture an event with group analytics.
444
421
 
445
- PHP
446
-
447
422
  ```php
448
423
  PostHog::capture([
449
424
  'distinctId' => 'user_distinct_id',
@@ -456,8 +431,6 @@ PostHog::capture([
456
431
 
457
432
  Use request context to apply a distinct ID, session ID, and common properties to all captures inside a callback. This is useful when connecting frontend activity to backend events, session replay, and error tracking.
458
433
 
459
- PHP
460
-
461
434
  ```php
462
435
  PostHog::withContext([
463
436
  'distinctId' => 'user_distinct_id',
@@ -472,12 +445,10 @@ PostHog::withContext([
472
445
  });
473
446
  ```
474
447
 
475
- You can extract PostHog context from frontend tracing headers with `contextFromHeaders()`. If you're using [PostHog JS](/docs/libraries/js.md) on the frontend, configure [`tracing_headers`](/docs/libraries/js/config.md#tracing-headers) for your PHP backend hostname so browser requests include the session and distinct ID headers.
448
+ You can extract PostHog context from frontend tracing headers with `contextFromHeaders()`. If you're using [PostHog JS](https://posthog.com/docs/libraries/js.md) on the frontend, configure [`tracing_headers`](https://posthog.com/docs/libraries/js/config.md#tracing-headers) for your PHP backend hostname so browser requests include the session and distinct ID headers.
476
449
 
477
450
  Then read the incoming headers on the server:
478
451
 
479
- PHP
480
-
481
452
  ```php
482
453
  $context = PostHog::contextFromHeaders($_SERVER);
483
454
 
@@ -498,8 +469,6 @@ The PHP SDK supports both manual exception capture and opt-in automatic error tr
498
469
 
499
470
  To automatically capture uncaught exceptions, PHP errors, and fatal shutdown errors, enable `error_tracking` when initializing the client:
500
471
 
501
- PHP
502
-
503
472
  ```php
504
473
  PostHog::init(
505
474
  '<ph_project_token>',
@@ -514,14 +483,12 @@ PostHog::init(
514
483
 
515
484
  You can also call `PostHog::captureException()` directly for manual capture. When source files are readable at runtime, PostHog includes surrounding source lines for in-app stack frames automatically.
516
485
 
517
- For the full setup guide, including `context_provider`, excluded exceptions, and verification steps, see the [PHP error tracking installation docs](/docs/error-tracking/installation/php.md).
486
+ For the full setup guide, including `context_provider`, excluded exceptions, and verification steps, see the [PHP error tracking installation docs](https://posthog.com/docs/error-tracking/installation/php.md).
518
487
 
519
488
  ## Config options
520
489
 
521
490
  When calling `PostHog::init`, there are various configuration options you can set apart from the host. Pass them into your client initialisation like so:
522
491
 
523
- PHP
524
-
525
492
  ```php
526
493
  PostHog::init(
527
494
  '<ph_project_token>',
@@ -543,7 +510,7 @@ All possible options below:
543
510
  | `timeout` **Type:** Integer **Default:** `10000` | Request timeout in milliseconds. |
544
511
  | `verify_batch_events_request` **Type:** Boolean **Default:** `true` | Whether to verify successful delivery of batch events (true, synchronous) or fire and forget (false, asynchronous) with the `lib_curl` consumer. |
545
512
  | `feature_flag_request_timeout_ms` **Type:** Integer **Default:** `3000` | Request timeout for feature flags in milliseconds. |
546
- | `flag_definition_cache_provider` **Type:** `PostHog\FlagDefinitionCacheProvider` **Default:** `null` | Provider for distributed local-evaluation flag definition caching. See [local evaluation in distributed environments](/docs/feature-flags/local-evaluation/distributed-environments?tab=PHP.md). |
513
+ | `flag_definition_cache_provider` **Type:** `PostHog\FlagDefinitionCacheProvider` **Default:** `null` | Provider for distributed local-evaluation flag definition caching. See [local evaluation in distributed environments](https://posthog.com/docs/feature-flags/local-evaluation/distributed-environments?tab=PHP.md). |
547
514
  | `maximum_backoff_duration` **Type:** Integer **Default:** `10000` | Request retry backoff. Retries stop after this duration is hit. |
548
515
  | `consumer` **Type:** String **Default:** `lib_curl` | One of `socket`, `file`, `lib_curl`, `fork_curl`, and `noop`. Determines what transport option to use for analytics capture. |
549
516
  | `debug` **Type:** Boolean **Default:** `false` | Output debug logs or not. |
@@ -552,7 +519,7 @@ All possible options below:
552
519
  | `compress_request` **Type:** Boolean/String **Default:** `false` | Whether to gzip batch request payloads. |
553
520
  | `error_handler` **Type:** Callable **Default:** `null` | Callback invoked for SDK transport errors. |
554
521
  | `filename` **Type:** String **Default:** `sys_get_temp_dir() . '/posthog.log'` | File path used when `consumer` is set to `file`. |
555
- | `error_tracking` **Type:** Array **Default:** `[]` | Enables automatic error tracking. See the options below or the [PHP error tracking setup guide](/docs/error-tracking/installation/php.md). |
522
+ | `error_tracking` **Type:** Array **Default:** `[]` | Enables automatic error tracking. See the options below or the [PHP error tracking setup guide](https://posthog.com/docs/error-tracking/installation/php.md). |
556
523
 
557
524
  ### Error tracking options
558
525
 
@@ -568,16 +535,12 @@ All possible options below:
568
535
 
569
536
  Call `PostHog::flush()` to send queued events without closing resources. When a script or long-running worker stops, call `PostHog::shutdown()` instead; it flushes queued events and releases resources held by providers such as `flag_definition_cache_provider`.
570
537
 
571
- PHP
572
-
573
538
  ```php
574
539
  PostHog::shutdown();
575
540
  ```
576
541
 
577
542
  ## Debug mode
578
543
 
579
- PHP
580
-
581
544
  ```php
582
545
  PostHog::init(
583
546
  '<ph_project_token>',
@@ -591,11 +554,3 @@ PostHog::init(
591
554
  ## Thank you
592
555
 
593
556
  This library is largely based on the `analytics-php` package.
594
-
595
- ### Still have questions?
596
-
597
- Ask PostHog AI
598
-
599
- ### Was this page useful?
600
-
601
- HelpfulCould be better
@@ -2,7 +2,7 @@
2
2
 
3
3
  # PostHog Python SDK
4
4
 
5
- **SDK Version:** 7.60.0
5
+ **SDK Version:** 7.73.1
6
6
 
7
7
  Integrate PostHog into any python application.
8
8
 
@@ -716,11 +716,11 @@ posthog.load_feature_flags()
716
716
 
717
717
  **Release Tag:** public
718
718
 
719
- Force a flush from the internal queue to the server. Do not use directly, call `shutdown()` instead.
719
+ Attempt immediate delivery of queued events and ended spans, keeping the client reusable. For a client shared across requests or serverless invocations (including the module-level client), call ``flush()`` before a short-lived invocation returns. Use ``shutdown()`` instead only for final process cleanup or when disposing of a client that will not be reused. Flush does not stop the background workers or feature flag poller, and does not end open spans. Returning does not guarantee server receipt: pending work can remain after a timeout or span export failure, and failed events may be dropped by the consumers. Calls made directly from SDK callbacks such as ``on_error`` are deferred rather than blocking the worker that invoked the callback.
720
720
 
721
721
  ### Parameters
722
722
 
723
- - **`timeout_seconds?`** (`float`) - Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely. Queued spans are sent at the same time, within the same
723
+ - **`timeout_seconds?`** (`float`) - Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass ``None`` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently. The span exporter waits up to this many seconds for an in-flight flush, then uses a fresh drain budget once it acquires the lock. If the lock wait times out, the in-flight flush is left to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. Each span request is bounded by the client's ``timeout`` in seconds, and the last request is not cut short. This is therefore not a strict wall-clock limit for the whole call. With ``None``, a retriable span failure is left for a later flush rather than retried within this call.
724
724
 
725
725
  ### Returns
726
726
 
@@ -729,8 +729,9 @@ Force a flush from the internal queue to the server. Do not use directly, call `
729
729
  ### Examples
730
730
 
731
731
  ```python
732
- posthog.capture('event_name')
733
- posthog.flush() # Ensures the event is sent immediately
732
+ posthog.capture('event_name', distinct_id='user_id')
733
+ # Before a serverless invocation returns; keep the shared client open.
734
+ posthog.flush(timeout_seconds=10)
734
735
  ```
735
736
 
736
737
  ---
@@ -791,7 +792,7 @@ posthog.join()
791
792
 
792
793
  **Release Tag:** public
793
794
 
794
- Flush all messages and cleanly shutdown the client. Call this before the process ends in serverless environments to avoid data loss. Normally this method blocks until queued events have been attempted and cleanup finishes. Failed or undrainable events may be dropped and reported through logging or ``on_error``; returning does not guarantee server receipt. Queued spans get one final flush of up to 30 s (plus a request already in flight); any it cannot send are discarded with a warning, as are spans still open. Lifecycle cleanup is attempted once, and cleanup failures are logged without retry. When called directly from an SDK callback such as ``on_error``, shutdown is deferred to avoid blocking the worker that invoked the callback. If the callback must coordinate a blocking shutdown, have it signal an application-owned thread and return before that thread calls shutdown. Do not wait inside the callback for another thread or task that calls a lifecycle method.
795
+ Attempt final delivery and permanently shut down the client. Call this for final process cleanup or when disposing of a client that will not be reused. It closes capture lanes, stops background workers and the feature flag poller, and tears down integrations. Do not call it at the end of each request or serverless invocation when the client is shared; call ``flush()`` before returning instead. A shut-down client cannot be reused; create a new client if needed. Normally this method blocks until queued events have been attempted and cleanup finishes. Failed or undrainable events may be dropped and reported through logging or ``on_error``; returning does not guarantee server receipt. Event draining has no timeout. Queued spans get one final flush with up to 30 seconds waiting for an in-flight flush, then a fresh 30-second drain budget; the last HTTP request is not cut short. Any spans it cannot send are discarded with a warning, as are spans still open. Lifecycle cleanup is attempted once, and cleanup failures are logged without retry. When called directly from an SDK callback such as ``on_error``, shutdown is deferred to avoid blocking the worker that invoked the callback. If the callback must coordinate a blocking shutdown, have it signal an application-owned thread and return before that thread calls shutdown. Do not wait inside the callback for another thread or task that calls a lifecycle method.
795
796
 
796
797
  ### Returns
797
798
 
@@ -1242,7 +1243,7 @@ Capture exception is idempotent - if it is called twice with the same exception
1242
1243
 
1243
1244
  ### Parameters
1244
1245
 
1245
- - **`exception`** (`BaseException`) - The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip.
1246
+ - **`exception`** (`BaseException`) - The exception to capture. If not provided, the current exception is captured via `sys.exc_info()` **kwargs: Optional capture arguments including distinct_id, properties, timestamp, uuid, groups, flags, send_feature_flags, and disable_geoip. Overriding reserved exception properties through ``properties`` is deprecated and will stop working in the next major version.
1246
1247
  - **`kwargs?`** (`Unpack[OptionalCaptureArgs]`)
1247
1248
 
1248
1249
  ### Returns
@@ -1558,11 +1559,11 @@ load_feature_flags()
1558
1559
 
1559
1560
  **Release Tag:** public
1560
1561
 
1561
- Tell the client to flush all queued events.
1562
+ Attempt immediate delivery of queued events and ended spans, keeping the global client reusable. Call ``flush()`` before a short-lived request or serverless invocation returns when using the shared module-level client. Use ``shutdown()`` only for final process cleanup or a client that will not be reused. Flush does not stop the background workers or feature flag poller, and does not end open spans. Returning does not guarantee server receipt: pending work can remain after a timeout or span export failure, and failed events may be dropped by consumers. Calls made directly from SDK callbacks such as ``on_error`` are deferred rather than blocking the worker that invoked the callback.
1562
1563
 
1563
1564
  ### Parameters
1564
1565
 
1565
- - **`timeout_seconds?`** (`float`) - Maximum seconds to wait for the queue to flush. Defaults to 10 seconds. Pass ``None`` to wait indefinitely.
1566
+ - **`timeout_seconds?`** (`float`) - Seconds to wait for event queues to drain, shared across event lanes. Defaults to 10 seconds. Pass ``None`` to wait without a time limit; this does not guarantee successful delivery. Queued spans flush concurrently, waiting up to this many seconds for an in-flight flush before starting a fresh drain budget. A lock wait timeout leaves the in-flight flush to finish. At least one span request is attempted after acquiring the lock, even with no budget left; retriable failures are retried after backoff while budget remains, with one last attempt at the deadline. The last span request is not cut short and is bounded by the client's ``timeout`` in seconds, so this is not a strict wall-clock limit for the whole call. With ``None``, a retriable span failure is left for a later flush rather than retried within this call.
1566
1567
 
1567
1568
  ### Returns
1568
1569
 
@@ -1571,8 +1572,10 @@ Tell the client to flush all queued events.
1571
1572
  ### Examples
1572
1573
 
1573
1574
  ```python
1574
- from posthog import flush
1575
- flush()
1575
+ import posthog
1576
+ posthog.capture('event_name', distinct_id='user_id')
1577
+ # Before a serverless invocation returns; keep the global client open.
1578
+ posthog.flush(timeout_seconds=10)
1576
1579
  ```
1577
1580
 
1578
1581
  ---
@@ -1600,7 +1603,7 @@ join()
1600
1603
 
1601
1604
  **Release Tag:** public
1602
1605
 
1603
- Flush all messages and cleanly shutdown the client. This normally blocks until queued events have been attempted and cleanup finishes. Failed or undrainable events may be dropped and reported through logging or ``on_error``; returning does not guarantee server receipt. Lifecycle cleanup is attempted once, and cleanup failures are logged without retry. Calls made directly from SDK callbacks such as ``on_error`` are deferred to avoid deadlocking the worker. If blocking completion is required, signal an application-owned thread, return from the callback, and call ``shutdown()`` from that thread. Do not wait inside a callback for another thread or task calling a lifecycle method.
1606
+ Attempt final delivery and permanently shut down the global client. Call this for final process cleanup, not at the end of each request or serverless invocation that shares the module-level client. Use ``flush()`` before returning from those invocations instead. Shutdown closes capture lanes, stops background workers and the feature flag poller, and tears down integrations. The global client is not recreated automatically after shutdown. This normally blocks until queued events have been attempted and cleanup finishes. Failed or undrainable events may be dropped and reported through logging or ``on_error``; returning does not guarantee server receipt. Event draining has no timeout. Queued spans get a final flush with up to 30 seconds waiting for an in-flight flush, then a fresh 30-second drain budget; the last HTTP request is not cut short. Unsent queued spans and still-open spans are discarded with a warning. Lifecycle cleanup is attempted once, and cleanup failures are logged without retry. Calls made directly from SDK callbacks such as ``on_error`` are deferred to avoid deadlocking the worker. If blocking completion is required, signal an application-owned thread, return from the callback, and call ``shutdown()`` from that thread. Do not wait inside a callback for another thread or task calling a lifecycle method.
1604
1607
 
1605
1608
  ### Returns
1606
1609