vybekiit 0.7.34 → 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.
- package/dist/bin.js +520 -9
- package/dist/global-skills/eas-app-stores/SKILL.md +2 -2
- package/dist/global-skills/eas-hosting/SKILL.md +2 -2
- package/dist/global-skills/eas-observe/SKILL.md +7 -15
- package/dist/global-skills/eas-observe/references/queries.md +51 -10
- package/dist/global-skills/eas-observe/references/setup.md +60 -7
- package/dist/global-skills/eas-simulator/SKILL.md +2 -2
- package/dist/global-skills/eas-simulator/references/run-your-app.md +2 -0
- package/dist/global-skills/eas-update/SKILL.md +2 -2
- package/dist/global-skills/eas-update-insights/SKILL.md +2 -2
- package/dist/global-skills/eas-workflows/SKILL.md +2 -2
- package/dist/global-skills/expo-animation/SKILL.md +2 -2
- package/dist/global-skills/expo-app-clip/SKILL.md +2 -2
- package/dist/global-skills/expo-brownfield/SKILL.md +2 -2
- package/dist/global-skills/expo-data-fetching/SKILL.md +2 -2
- package/dist/global-skills/expo-design-system/SKILL.md +2 -2
- package/dist/global-skills/expo-dev-client/SKILL.md +4 -2
- package/dist/global-skills/expo-dom/SKILL.md +2 -2
- package/dist/global-skills/expo-examples/SKILL.md +2 -2
- package/dist/global-skills/expo-migrate-module/SKILL.md +2 -2
- package/dist/global-skills/expo-module/SKILL.md +2 -2
- package/dist/global-skills/expo-native-ui/SKILL.md +2 -2
- package/dist/global-skills/expo-overview/SKILL.md +9 -4
- package/dist/global-skills/expo-overview/references/launch-without-dev-menu.md +24 -0
- package/dist/global-skills/expo-project-structure/SKILL.md +2 -2
- package/dist/global-skills/expo-router/SKILL.md +2 -2
- package/dist/global-skills/expo-ui/SKILL.md +2 -2
- package/dist/global-skills/expo-upgrade/SKILL.md +2 -2
- package/dist/global-skills/expo-web-to-native/SKILL.md +2 -2
- package/dist/global-skills/expo-web-to-native/references/verify-on-device.md +1 -1
- package/dist/global-skills/firebase-app-hosting-basics/SKILL.md +16 -3
- package/dist/global-skills/firebase-app-hosting-basics/references/cli_commands.md +10 -12
- package/dist/global-skills/firebase-app-hosting-basics/references/configuration.md +2 -1
- package/dist/global-skills/firebase-basics/SKILL.md +6 -4
- package/dist/global-skills/firebase-basics/references/web_setup.md +3 -3
- package/dist/global-skills/instrument-feature-flags/references/adding-feature-flag-code.md +81 -333
- package/dist/global-skills/instrument-feature-flags/references/android.md +19 -13
- package/dist/global-skills/instrument-feature-flags/references/api.md +17 -13
- package/dist/global-skills/instrument-feature-flags/references/best-practices.md +35 -35
- package/dist/global-skills/instrument-feature-flags/references/django.md +120 -72
- package/dist/global-skills/instrument-feature-flags/references/dotnet.md +48 -102
- package/dist/global-skills/instrument-feature-flags/references/elixir.md +4 -10
- package/dist/global-skills/instrument-feature-flags/references/flask.md +55 -39
- package/dist/global-skills/instrument-feature-flags/references/flutter.md +19 -13
- package/dist/global-skills/instrument-feature-flags/references/go.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/ios.md +19 -13
- package/dist/global-skills/instrument-feature-flags/references/java.md +4 -12
- package/dist/global-skills/instrument-feature-flags/references/laravel.md +18 -16
- package/dist/global-skills/instrument-feature-flags/references/next-js.md +44 -54
- package/dist/global-skills/instrument-feature-flags/references/nodejs.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/php.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/python.md +22 -14
- package/dist/global-skills/instrument-feature-flags/references/react-native.md +18 -13
- package/dist/global-skills/instrument-feature-flags/references/react.md +21 -14
- package/dist/global-skills/instrument-feature-flags/references/ruby-on-rails.md +31 -68
- package/dist/global-skills/instrument-feature-flags/references/ruby.md +21 -13
- package/dist/global-skills/instrument-feature-flags/references/rust.md +10 -34
- package/dist/global-skills/instrument-feature-flags/references/usage.md +94 -114
- package/dist/global-skills/instrument-feature-flags/references/web.md +21 -13
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-android.md +7 -7
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-expo.md +2 -2
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-fastapi.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-flask.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-laravel.md +2 -2
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-php.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-python.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-ruby.md +1 -1
- package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-swift.md +4 -4
- package/dist/global-skills/instrument-product-analytics/references/android.md +64 -109
- package/dist/global-skills/instrument-product-analytics/references/angular.md +32 -28
- package/dist/global-skills/instrument-product-analytics/references/astro.md +29 -34
- package/dist/global-skills/instrument-product-analytics/references/configuration.md +27 -42
- package/dist/global-skills/instrument-product-analytics/references/django.md +120 -72
- package/dist/global-skills/instrument-product-analytics/references/dotnet.md +48 -102
- package/dist/global-skills/instrument-product-analytics/references/elixir.md +25 -50
- package/dist/global-skills/instrument-product-analytics/references/flask.md +55 -39
- package/dist/global-skills/instrument-product-analytics/references/flutter.md +94 -96
- package/dist/global-skills/instrument-product-analytics/references/go.md +39 -77
- package/dist/global-skills/instrument-product-analytics/references/identify-users.md +24 -26
- package/dist/global-skills/instrument-product-analytics/references/ios.md +22 -22
- package/dist/global-skills/instrument-product-analytics/references/laravel.md +18 -16
- package/dist/global-skills/instrument-product-analytics/references/next-js.md +44 -54
- package/dist/global-skills/instrument-product-analytics/references/nuxt-js-3-6.md +32 -34
- package/dist/global-skills/instrument-product-analytics/references/nuxt-js.md +36 -36
- package/dist/global-skills/instrument-product-analytics/references/php.md +42 -87
- package/dist/global-skills/instrument-product-analytics/references/posthog-python.md +15 -12
- package/dist/global-skills/instrument-product-analytics/references/python.md +106 -154
- package/dist/global-skills/instrument-product-analytics/references/react-native.md +97 -176
- package/dist/global-skills/instrument-product-analytics/references/react-router-v6.md +29 -40
- package/dist/global-skills/instrument-product-analytics/references/react-router-v7-data-mode.md +29 -38
- package/dist/global-skills/instrument-product-analytics/references/react-router-v7-declarative-mode.md +29 -40
- package/dist/global-skills/instrument-product-analytics/references/react-router-v7-framework-mode.md +32 -37
- package/dist/global-skills/instrument-product-analytics/references/ruby-on-rails.md +31 -68
- package/dist/global-skills/instrument-product-analytics/references/ruby.md +40 -96
- package/dist/global-skills/instrument-product-analytics/references/svelte.md +34 -34
- package/dist/global-skills/instrument-product-analytics/references/tanstack-start.md +19 -19
- package/dist/global-skills/instrument-product-analytics/references/usage.md +94 -114
- package/dist/global-skills/instrument-product-analytics/references/vue-js.md +33 -45
- package/dist/global-skills/mongodb-search-and-ai/SKILL.md +40 -22
- package/dist/global-skills/mongodb-search-and-ai/references/automated-embedding.md +8 -2
- package/dist/global-skills/mongodb-search-and-ai/references/quick-start.md +725 -0
- package/dist/global-skills/mongodb-search-and-ai/scripts/quickstart_complete.py +386 -0
- package/dist/global-skills/neon/references/claimable-neon.md +2 -0
- package/dist/global-skills/neon-realtime/references/queries.md +2 -2
- package/dist/global-skills/resend/SKILL.md +1 -1
- package/dist/global-skills/resend/references/inboxes.md +49 -21
- package/dist/global-skills/resend/references/webhooks.md +1 -1
- package/dist/global-skills/stripe-best-practices/SKILL.md +1 -1
- package/dist/global-skills/stripe-best-practices/references/connect.md +1 -1
- package/dist/global-skills/stripe-best-practices/references/security.md +9 -9
- package/dist/global-skills/vybekiitReferences/backend/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/backend/agent/goal-routes.json +303 -18
- package/dist/global-skills/vybekiitReferences/extension/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/extension/agent/goal-routes.json +352 -18
- package/dist/global-skills/vybekiitReferences/mobile/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/mobile/agent/goal-routes.json +413 -22
- package/dist/global-skills/vybekiitReferences/spa/AGENTS.md +1 -1
- package/dist/global-skills/vybekiitReferences/spa/agent/goal-routes.json +391 -21
- package/dist/global-skills/vybekiitReferences/web/AGENTS.md +14 -2
- package/dist/global-skills/vybekiitReferences/web/agent/goal-routes.json +490 -32
- package/package.json +8 -8
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
# Elixir
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/elixir
|
|
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).
|
|
8
|
+
|
|
9
|
+
## On this page
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Identifying users](#identifying-users)
|
|
13
|
+
- [Capturing events](#capturing-events)
|
|
14
|
+
- [Request context](#request-context)
|
|
15
|
+
- [Feature flags](#feature-flags)
|
|
16
|
+
- [Error tracking](#error-tracking)
|
|
17
|
+
- [Advanced configuration](#advanced-configuration)
|
|
18
|
+
- [Thanks](#thanks)
|
|
19
|
+
|
|
5
20
|
This library provides an Elixir HTTP client for PostHog. [See the repository](https://github.com/posthog/posthog-elixir) for more information.
|
|
6
21
|
|
|
7
22
|
## Installation
|
|
@@ -10,8 +25,6 @@ This library provides an Elixir HTTP client for PostHog. [See the repository](ht
|
|
|
10
25
|
|
|
11
26
|
The package can be installed by adding `posthog` to your list of dependencies in `mix.exs`:
|
|
12
27
|
|
|
13
|
-
Elixir
|
|
14
|
-
|
|
15
28
|
```elixir
|
|
16
29
|
def deps do
|
|
17
30
|
[
|
|
@@ -42,16 +55,14 @@ For a test environment, you can pass in `test_mode: true` value to the config. T
|
|
|
42
55
|
|
|
43
56
|
## Identifying users
|
|
44
57
|
|
|
45
|
-
> **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).
|
|
58
|
+
> **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).
|
|
46
59
|
>
|
|
47
|
-
> See our guide on [identifying users](/docs/getting-started/identify-users.md) for how to set this up.
|
|
60
|
+
> See our guide on [identifying users](https://posthog.com/docs/getting-started/identify-users.md) for how to set this up.
|
|
48
61
|
|
|
49
62
|
## Capturing events
|
|
50
63
|
|
|
51
64
|
To capture an event, use `PostHog.capture/2`:
|
|
52
65
|
|
|
53
|
-
Elixir
|
|
54
|
-
|
|
55
66
|
```elixir
|
|
56
67
|
PostHog.capture("user_signed_up", %{distinct_id: "distinct_id_of_the_user"})
|
|
57
68
|
```
|
|
@@ -60,9 +71,7 @@ PostHog.capture("user_signed_up", %{distinct_id: "distinct_id_of_the_user"})
|
|
|
60
71
|
|
|
61
72
|
### Setting event properties
|
|
62
73
|
|
|
63
|
-
Optionally, you can include additional information with the event by including a [properties](/docs/data/events.md#event-properties) object:
|
|
64
|
-
|
|
65
|
-
Elixir
|
|
74
|
+
Optionally, you can include additional information with the event by including a [properties](https://posthog.com/docs/data/events.md#event-properties) object:
|
|
66
75
|
|
|
67
76
|
```elixir
|
|
68
77
|
PostHog.capture("user_signed_up", %{
|
|
@@ -78,8 +87,6 @@ Carrying `distinct_id` around all the time might not be the most convenient appr
|
|
|
78
87
|
|
|
79
88
|
The context is stored in the `Logger` metadata and PostHog automatically attaches these properties to any events you capture with `PostHog.capture/2`, as long as they happen in the same process.
|
|
80
89
|
|
|
81
|
-
Elixir
|
|
82
|
-
|
|
83
90
|
```elixir
|
|
84
91
|
PostHog.set_context(%{distinct_id: "distinct_id_of_the_user"})
|
|
85
92
|
PostHog.capture("page_opened")
|
|
@@ -87,8 +94,6 @@ PostHog.capture("page_opened")
|
|
|
87
94
|
|
|
88
95
|
You can also scope the context to a specific event name:
|
|
89
96
|
|
|
90
|
-
Elixir
|
|
91
|
-
|
|
92
97
|
```elixir
|
|
93
98
|
PostHog.set_event_context("sensitive_event", %{"$process_person_profile": false})
|
|
94
99
|
```
|
|
@@ -107,16 +112,12 @@ For example:
|
|
|
107
112
|
|
|
108
113
|
#### Create alias
|
|
109
114
|
|
|
110
|
-
Elixir
|
|
111
|
-
|
|
112
115
|
```elixir
|
|
113
116
|
PostHog.capture("$create_alias", %{distinct_id: "frontend_id", alias: "backend_id"})
|
|
114
117
|
```
|
|
115
118
|
|
|
116
119
|
#### Group analytics
|
|
117
120
|
|
|
118
|
-
Elixir
|
|
119
|
-
|
|
120
121
|
```elixir
|
|
121
122
|
PostHog.capture("$groupidentify", %{
|
|
122
123
|
distinct_id: "static_string_used_for_all_group_events",
|
|
@@ -138,8 +139,6 @@ plug MyAppWeb.Router
|
|
|
138
139
|
|
|
139
140
|
For plain Plug routers, add it before `:match` and `:dispatch`:
|
|
140
141
|
|
|
141
|
-
Elixir
|
|
142
|
-
|
|
143
142
|
```elixir
|
|
144
143
|
defmodule MyRouter do
|
|
145
144
|
use Plug.Router
|
|
@@ -154,13 +153,13 @@ end
|
|
|
154
153
|
|
|
155
154
|
The plug adds request metadata such as `$current_url`, `$host`, `$pathname`, `$request_method`, `$user_agent`, and `$ip`. It also reads `X-PostHog-Distinct-Id` and `X-PostHog-Session-Id` as analytics context so backend events and errors can be linked to frontend users and sessions.
|
|
156
155
|
|
|
157
|
-
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 Phoenix or Plug backend hostname so browser requests include these headers.
|
|
156
|
+
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 Phoenix or Plug backend hostname so browser requests include these headers.
|
|
158
157
|
|
|
159
158
|
Tracing headers are client-controlled analytics context, not authentication or authorization. Pass an authenticated `distinct_id` explicitly for security-sensitive server-side decisions.
|
|
160
159
|
|
|
161
160
|
## Feature flags
|
|
162
161
|
|
|
163
|
-
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.
|
|
162
|
+
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.
|
|
164
163
|
|
|
165
164
|
There are two steps to implement feature flags in Elixir:
|
|
166
165
|
|
|
@@ -170,8 +169,6 @@ Call `PostHog.FeatureFlags.evaluate_flags/1` once for the user, then read values
|
|
|
170
169
|
|
|
171
170
|
#### Boolean feature flags
|
|
172
171
|
|
|
173
|
-
Elixir
|
|
174
|
-
|
|
175
172
|
```elixir
|
|
176
173
|
{:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
|
|
177
174
|
|
|
@@ -184,8 +181,6 @@ end
|
|
|
184
181
|
|
|
185
182
|
#### Multivariate feature flags
|
|
186
183
|
|
|
187
|
-
Elixir
|
|
188
|
-
|
|
189
184
|
```elixir
|
|
190
185
|
{:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
|
|
191
186
|
|
|
@@ -204,9 +199,9 @@ end
|
|
|
204
199
|
|
|
205
200
|
### Step 2: Include feature flag information when capturing events
|
|
206
201
|
|
|
207
|
-
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.
|
|
202
|
+
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.
|
|
208
203
|
|
|
209
|
-
> **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
|
|
204
|
+
> **Note:** This step is only required for events captured using our server-side SDKs or [API](https://posthog.com/docs/api.md).
|
|
210
205
|
|
|
211
206
|
There are two methods you can use to include feature flag information in your events:
|
|
212
207
|
|
|
@@ -214,8 +209,6 @@ There are two methods you can use to include feature flag information in your ev
|
|
|
214
209
|
|
|
215
210
|
Put the same `snapshot` object that you used for branching into context. Subsequent captures from the same process attach the exact flag values from that evaluation and don't make another `/flags` request.
|
|
216
211
|
|
|
217
|
-
Elixir
|
|
218
|
-
|
|
219
212
|
```elixir
|
|
220
213
|
{:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
|
|
221
214
|
|
|
@@ -231,8 +224,6 @@ By default, this attaches every flag in the snapshot using `$feature/<flag-key>`
|
|
|
231
224
|
|
|
232
225
|
To reduce event property bloat, put a filtered snapshot in context:
|
|
233
226
|
|
|
234
|
-
Elixir
|
|
235
|
-
|
|
236
227
|
```elixir
|
|
237
228
|
{:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
|
|
238
229
|
|
|
@@ -254,8 +245,6 @@ PostHog.FeatureFlags.set_in_context(
|
|
|
254
245
|
|
|
255
246
|
In the event properties, include `$feature/feature_flag_name: variant_key`:
|
|
256
247
|
|
|
257
|
-
Elixir
|
|
258
|
-
|
|
259
248
|
```elixir
|
|
260
249
|
PostHog.capture("event_name", %{
|
|
261
250
|
"$feature/feature-flag-key" => "variant-key",
|
|
@@ -267,8 +256,6 @@ PostHog.capture("event_name", %{
|
|
|
267
256
|
|
|
268
257
|
By default, `evaluate_flags/1` evaluates every flag for the user. If you only need a few flags, pass `flag_keys` to request only those flags:
|
|
269
258
|
|
|
270
|
-
Elixir
|
|
271
|
-
|
|
272
259
|
```elixir
|
|
273
260
|
{:ok, snapshot} =
|
|
274
261
|
PostHog.FeatureFlags.evaluate_flags(%{
|
|
@@ -279,13 +266,13 @@ Elixir
|
|
|
279
266
|
|
|
280
267
|
### Sending `$feature_flag_called` events
|
|
281
268
|
|
|
282
|
-
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 `evaluate_flags/1`, the SDK sends this event when you call `PostHog.FeatureFlags.Evaluations.enabled?/2` or `PostHog.FeatureFlags.Evaluations.get_flag/2` for a flag.
|
|
269
|
+
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 `evaluate_flags/1`, the SDK sends this event when you call `PostHog.FeatureFlags.Evaluations.enabled?/2` or `PostHog.FeatureFlags.Evaluations.get_flag/2` for a flag.
|
|
283
270
|
|
|
284
271
|
`PostHog.FeatureFlags.Evaluations.get_flag_payload/2` doesn't send `$feature_flag_called` events.
|
|
285
272
|
|
|
286
273
|
### Local feature flag evaluation
|
|
287
274
|
|
|
288
|
-
Local evaluation is available in version 2.15.0 and later. Follow the [server-side local evaluation guide](/docs/feature-flags/local-evaluation.md) to find your secure key and see how to pass the person properties, groups, and group properties that your flag conditions require.
|
|
275
|
+
Local evaluation is available in version 2.15.0 and later. Follow the [server-side local evaluation guide](https://posthog.com/docs/feature-flags/local-evaluation.md) to find your secure key and see how to pass the person properties, groups, and group properties that your flag conditions require.
|
|
289
276
|
|
|
290
277
|
Store the secure key in a server-side environment variable. Don't expose it to client-side applications:
|
|
291
278
|
|
|
@@ -309,7 +296,7 @@ Use these configuration options to control local evaluation:
|
|
|
309
296
|
| `flag_definition_request_timeout_ms` | `10_000` | Sets the timeout for each definition request. |
|
|
310
297
|
| `flag_definition_cache_provider_timeout_ms` | `5_000` | Sets the timeout for each shared cache provider callback. |
|
|
311
298
|
|
|
312
|
-
For multiple server instances, you can implement `PostHog.FeatureFlags.FlagDefinitionCacheProvider` and set `flag_definition_cache_provider: {module, state}`. This optional provider shares definitions and coordinates which instance polls PostHog. See [local evaluation in distributed environments](/docs/feature-flags/local-evaluation/distributed-environments?tab=Elixir.md) for the callback contract and configuration.
|
|
299
|
+
For multiple server instances, you can implement `PostHog.FeatureFlags.FlagDefinitionCacheProvider` and set `flag_definition_cache_provider: {module, state}`. This optional provider shares definitions and coordinates which instance polls PostHog. See [local evaluation in distributed environments](https://posthog.com/docs/feature-flags/local-evaluation/distributed-environments?tab=Elixir.md) for the callback contract and configuration.
|
|
313
300
|
|
|
314
301
|
## Error tracking
|
|
315
302
|
|
|
@@ -319,8 +306,6 @@ As a matter of fact, since this is built on top of Elixir's `Logger` module, it
|
|
|
319
306
|
|
|
320
307
|
You can always disable it by setting `enable_error_tracking` to false:
|
|
321
308
|
|
|
322
|
-
Elixir
|
|
323
|
-
|
|
324
309
|
```elixir
|
|
325
310
|
config :posthog,
|
|
326
311
|
enable_error_tracking: false
|
|
@@ -399,8 +384,6 @@ end
|
|
|
399
384
|
|
|
400
385
|
Then, each function in the PostHog module accepts an optional first argument with the name of the PostHog supervisor tree that will process the capture:
|
|
401
386
|
|
|
402
|
-
Elixir
|
|
403
|
-
|
|
404
387
|
```elixir
|
|
405
388
|
PostHog.capture(AnotherPostHog, "user_signed_up", %{distinct_id: "user123"})
|
|
406
389
|
```
|
|
@@ -408,11 +391,3 @@ PostHog.capture(AnotherPostHog, "user_signed_up", %{distinct_id: "user123"})
|
|
|
408
391
|
## Thanks
|
|
409
392
|
|
|
410
393
|
The library is maintained by the PostHog team since February 2025. Thanks to [nkezhaya](https://github.com/nkezhaya) for contributing v0.1.0. Thanks to [martosaur](https://github.com/martosaur) for contributing v2.0.0.
|
|
411
|
-
|
|
412
|
-
### Still have questions?
|
|
413
|
-
|
|
414
|
-
Ask PostHog AI
|
|
415
|
-
|
|
416
|
-
### Was this page useful?
|
|
417
|
-
|
|
418
|
-
HelpfulCould be better
|
|
@@ -2,9 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
# Flask
|
|
4
4
|
|
|
5
|
+
Canonical URL: https://posthog.com/docs/libraries/flask
|
|
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
|
+
- [Request contexts](#request-contexts)
|
|
14
|
+
- [Error tracking](#error-tracking)
|
|
15
|
+
- [Next steps](#next-steps)
|
|
16
|
+
- [Supported versions](#supported-versions)
|
|
17
|
+
|
|
5
18
|
PostHog makes it easy to get data about traffic and usage of your Flask app. Integrating PostHog enables analytics, custom events capture, feature flags, error tracking, and more.
|
|
6
19
|
|
|
7
|
-
This guide walks you through integrating PostHog into your Flask app using the [Python SDK](/docs/libraries/python.md).
|
|
20
|
+
This guide walks you through integrating PostHog into your Flask app using the [Python SDK](https://posthog.com/docs/libraries/python.md).
|
|
8
21
|
|
|
9
22
|
> These docs cover version `7.x` of the Python SDK, which requires Python 3.10 or higher. On Python 3.9? See [supported versions](#supported-versions).
|
|
10
23
|
|
|
@@ -44,8 +57,6 @@ You can find your project token and instance address in [your project settings](
|
|
|
44
57
|
>
|
|
45
58
|
> In Python, you can do this through a context. All event captures in the same context will be tagged automatically with the correct `distinct_id`. Typically, you would set a fresh context and identify at the top of each route.
|
|
46
59
|
>
|
|
47
|
-
> Python
|
|
48
|
-
>
|
|
49
60
|
> ```python
|
|
50
61
|
> from posthog import new_context, identify_context, capture
|
|
51
62
|
>
|
|
@@ -61,45 +72,58 @@ You can find your project token and instance address in [your project settings](
|
|
|
61
72
|
|
|
62
73
|
## Request contexts
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
If you're using [PostHog JavaScript Web](/docs/libraries/js.md) on the frontend, configure [`tracing_headers`](/docs/libraries/js/config.md#tracing-headers) for your Flask backend hostname so browser requests include the session and distinct ID headers.
|
|
75
|
+
Version `7.69.0` and later of the Python SDK includes a Flask integration that creates a fresh [context](https://posthog.com/docs/libraries/python.md#contexts) for every request. It adds the request URL, method, path, route, IP address, and user agent to events captured during the request.
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
Register the integration after you create your Flask app and PostHog client:
|
|
69
78
|
|
|
70
|
-
|
|
79
|
+
app.py
|
|
71
80
|
|
|
72
81
|
```python
|
|
73
|
-
from flask import
|
|
74
|
-
from posthog import identify_context, set_context_session, tag
|
|
82
|
+
from posthog.integrations.flask import PosthogFlaskIntegration
|
|
75
83
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
PosthogFlaskIntegration(
|
|
85
|
+
app,
|
|
86
|
+
client=posthog,
|
|
87
|
+
capture_exceptions=True,
|
|
88
|
+
)
|
|
89
|
+
```
|
|
82
90
|
|
|
83
|
-
|
|
84
|
-
if session_id:
|
|
85
|
-
set_context_session(session_id)
|
|
91
|
+
Setting `capture_exceptions=True` captures unhandled Flask exceptions. Set it to `False` for request enrichment without automatic exception capture. If you omit it, the integration inherits the client's `enable_exception_autocapture` setting.
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
tag('$request_method', request.method)
|
|
89
|
-
tag('$request_path', request.path)
|
|
93
|
+
You can also provide:
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
- `request_filter` to skip both enrichment and automatic exception capture for selected requests
|
|
96
|
+
- `extra_properties` to add application-specific properties to the request context
|
|
97
|
+
- `trust_tracing_headers` to accept PostHog session and distinct ID headers
|
|
92
98
|
|
|
93
|
-
|
|
99
|
+
If you're using [PostHog JavaScript Web](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 Flask backend hostname so browser requests include the session and distinct ID headers.
|
|
100
|
+
|
|
101
|
+
The integration ignores these headers by default because clients can control them. Set `trust_tracing_headers=True` when registering the integration to accept them as analytics context. Don't use them for authentication or authorization.
|
|
102
|
+
|
|
103
|
+
Identify the request context from your route when you have an authenticated user ID:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from flask import session
|
|
107
|
+
from posthog import identify_context
|
|
108
|
+
|
|
109
|
+
@app.route("/api/dashboard", methods=["POST"])
|
|
110
|
+
def api_dashboard():
|
|
111
|
+
user_id = session.get("user_id")
|
|
112
|
+
if user_id:
|
|
113
|
+
identify_context(str(user_id))
|
|
114
|
+
|
|
115
|
+
posthog.capture("dashboard_api_called")
|
|
116
|
+
|
|
117
|
+
return "", 204
|
|
94
118
|
```
|
|
95
119
|
|
|
96
|
-
Events captured without a context or explicit `distinct_id` are sent as [anonymous events](/docs/data/anonymous-vs-identified-events.md) with an auto-generated `distinct_id`. See the [Python SDK docs](/docs/libraries/python.md#person-profiles-and-properties) for more details.
|
|
120
|
+
Events captured without a context or explicit `distinct_id` are sent as [anonymous events](https://posthog.com/docs/data/anonymous-vs-identified-events.md) with an auto-generated `distinct_id`. See the [Python SDK docs](https://posthog.com/docs/libraries/python.md#person-profiles-and-properties) for more details.
|
|
97
121
|
|
|
98
122
|
## Error tracking
|
|
99
123
|
|
|
100
|
-
|
|
124
|
+
`PosthogFlaskIntegration` captures unhandled exceptions when you set `capture_exceptions=True` or enable exception autocapture on its client. It doesn't capture expected HTTP exceptions or exceptions consumed by your application's error handlers.
|
|
101
125
|
|
|
102
|
-
|
|
126
|
+
Call `capture_exception()` from a custom error handler when you want to report a handled exception:
|
|
103
127
|
|
|
104
128
|
```python
|
|
105
129
|
from flask import Flask, jsonify
|
|
@@ -122,13 +146,13 @@ def handle_exception(e):
|
|
|
122
146
|
|
|
123
147
|
## Next steps
|
|
124
148
|
|
|
125
|
-
For any technical questions for how to integrate specific PostHog features into Flask (such as analytics, feature flags, A/B testing, etc.), have a look at our [Python SDK docs](/docs/libraries/python.md).
|
|
149
|
+
For any technical questions for how to integrate specific PostHog features into Flask (such as analytics, feature flags, A/B testing, etc.), have a look at our [Python SDK docs](https://posthog.com/docs/libraries/python.md).
|
|
126
150
|
|
|
127
151
|
Alternatively, the following tutorials can help you get started:
|
|
128
152
|
|
|
129
|
-
- [How to set up analytics in Python and Flask](/tutorials/python-analytics.md)
|
|
130
|
-
- [How to set up feature flags in Python and Flask](/tutorials/python-feature-flags.md)
|
|
131
|
-
- [How to set up A/B tests in Python and Flask](/tutorials/python-ab-testing.md)
|
|
153
|
+
- [How to set up analytics in Python and Flask](https://posthog.com/tutorials/python-analytics.md)
|
|
154
|
+
- [How to set up feature flags in Python and Flask](https://posthog.com/tutorials/python-feature-flags.md)
|
|
155
|
+
- [How to set up A/B tests in Python and Flask](https://posthog.com/tutorials/python-ab-testing.md)
|
|
132
156
|
|
|
133
157
|
## Supported versions
|
|
134
158
|
|
|
@@ -137,11 +161,3 @@ These docs cover version `7.x` of the PostHog Python SDK, which requires Python
|
|
|
137
161
|
Everything on this page works the same way on `6.9.3`. Event capture, the context API (`new_context`, `identify_context`, `set_context_session`), and `PosthogContextMiddleware` are identical on `6.9.3` and `7.0.0` — `7.0.0` only dropped Python 3.9 and bumped the optional LLM provider SDKs. That includes the middleware identifying the request context from the `X-POSTHOG-DISTINCT-ID` header and falling back to the authenticated user, which behaves the same across both lines.
|
|
138
162
|
|
|
139
163
|
Later `7.x` releases add what the 6.x line does not receive, such as the Celery integration, tracing header sanitization, and `set_context_device_id`. They also changed the middleware's own captured properties: `7.x` sends the request IP as `$ip`, where `6.9.3` sends it as `$ip_address`, and `7.x` additionally captures `$request_path`, `$raw_user_agent`, and the authenticated user's `email`.
|
|
140
|
-
|
|
141
|
-
### Still have questions?
|
|
142
|
-
|
|
143
|
-
Ask PostHog AI
|
|
144
|
-
|
|
145
|
-
### Was this page useful?
|
|
146
|
-
|
|
147
|
-
HelpfulCould be better
|