Skip to content

Commit 619cb87

Browse files
authored
tracing headers now an array (#14160)
1 parent 6ed1208 commit 619cb87

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

contents/docs/data/sessions.mdx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ A session can span multiple tabs and windows, but only on the same browser and d
3232

3333
Activity is defined as any event sent from the client including autocapture events and replay activity like mouse movement. The inactivity period can be configured using the `session_idle_timeout_seconds` [configuration option](/docs/libraries/js/config).
3434

35-
> **Note:** If you are [migrating data](/docs/migrate) or [using a CDP](/docs/advanced/cdp), you may need to manually set the `$session_id` property if you want to query sessions or connect them to session replays.
35+
> **Note:** If you are [migrating data](/docs/migrate) or [using a CDP](/docs/advanced/cdp), you may need to manually set the `$session_id` property if you want to query sessions or connect them to session replays.
3636
> If you are using the JavaScript Web SDK alongside your CDP, you can get this value by calling `posthog.get_session_id()`.
3737
3838
## Session properties
@@ -86,9 +86,9 @@ The easiest way to analyze a session is to view a [session replay](/docs/session
8686
[Web analytics](/docs/web-analytics) also gives you an easily accessible overview. The top section contains sessions, session duration, and bounce rate, while further down provides more details on entry paths, exit paths, top channels, device types, and more.
8787

8888
<ProductScreenshot
89-
imageLight = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716841744/posthog.com/contents/images/docs/user-guides/sessions/web-light.png"
89+
imageLight = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716841744/posthog.com/contents/images/docs/user-guides/sessions/web-light.png"
9090
imageDark = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716841744/posthog.com/contents/images/docs/user-guides/sessions/web-dark.png"
91-
alt="Session data in web analytics"
91+
alt="Session data in web analytics"
9292
classes="rounded"
9393
/>
9494

@@ -103,18 +103,18 @@ This provides the count of unique sessions where the specified event occurred. T
103103
To do this, select **Unique sessions** from the aggregation dropdown.
104104

105105
<ProductScreenshot
106-
imageLight = {uniqueSessionLight}
106+
imageLight = {uniqueSessionLight}
107107
imageDark = {uniqueSessionDark}
108-
alt="Session counts"
108+
alt="Session counts"
109109
classes="rounded"
110110
/>
111111

112112
This can then be used in a formula to understand things like the average number of sessions per user or the average number of events per session.
113113

114114
<ProductScreenshot
115-
imageLight = {sessionFormulaLight}
115+
imageLight = {sessionFormulaLight}
116116
imageDark = {sessionFormulaDark}
117-
alt="Session formula"
117+
alt="Session formula"
118118
classes="rounded"
119119
/>
120120

@@ -123,9 +123,9 @@ This can then be used in a formula to understand things like the average number
123123
You can use any of the session properties to filter your data. For example, to remove sessions that are shorter than 10 seconds, you can filter for sessions where duration is greater than 10 seconds.
124124

125125
<ProductScreenshot
126-
imageLight = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716848579/posthog.com/contents/images/docs/user-guides/sessions/duration-light.png"
126+
imageLight = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716848579/posthog.com/contents/images/docs/user-guides/sessions/duration-light.png"
127127
imageDark = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716848579/posthog.com/contents/images/docs/user-guides/sessions/duration-dark.png"
128-
alt="Session duration filter"
128+
alt="Session duration filter"
129129
classes="rounded"
130130
/>
131131

@@ -134,9 +134,9 @@ You can use any of the session properties to filter your data. For example, to r
134134
You can plot session properties over time like you would with an event count. To do this, select one of the property aggregators (e.g. median, 90th percentile, etc.) and then select the session property to plot. For example, to plot the median session duration, select **Property value median** and then select **Session duration** as the property.
135135

136136
<ProductScreenshot
137-
imageLight = {medianDurationLight}
137+
imageLight = {medianDurationLight}
138138
imageDark = {medianDurationDark}
139-
alt="Session median duration"
139+
alt="Session median duration"
140140
classes="rounded"
141141
/>
142142

@@ -149,7 +149,7 @@ This is useful for understanding entry URLs or UTMs. For example, to break down
149149
<ProductScreenshot
150150
imageLight = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716849942/posthog.com/contents/images/docs/user-guides/sessions/entry-light.png"
151151
imageDark = "https://res.cloudinary.com/dmukukwp6/image/upload/v1716849942/posthog.com/contents/images/docs/user-guides/sessions/entry-dark.png"
152-
alt="Entry URL breakdown"
152+
alt="Entry URL breakdown"
153153
classes="rounded"
154154
/>
155155

@@ -163,11 +163,11 @@ If the events are logically part of the same session, e.g. a user starts a purch
163163

164164
### Automatically sending session IDs
165165

166-
If you enable tracing headers within the JavaScript SDK, the session ID will be sent on every request.
166+
If you enable tracing headers within the JavaScript SDK, the session ID will be sent on every request. You can enable tracing headers by adding the `__add_tracing_headers` option to your `posthog.init` call:
167167

168168
```ts
169169
posthog.init('<ph_project_api_key>', {
170-
__add_tracing_headers: true
170+
__add_tracing_headers: ['your-backend-domain.com'] // +
171171
})
172172
```
173173

contents/docs/libraries/python/_snippets/contexts.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ with new_context():
9494

9595
It's recommended to pass the currently active distinct ID from the frontend to the backend, using the `X-POSTHOG-DISTINCT-ID` header. If you're using our Django middleware, this is extracted and associated with the request handler context automatically.
9696

97-
You can read more about identifying users in the [user identification documentation](/docs/product-analytics/identify).
97+
You can read more about identifying users in the [user identification documentation](/docs/product-analytics/identify).
9898

9999
### Contexts and sessions
100100

@@ -108,7 +108,16 @@ with new_context():
108108

109109
<CalloutBox icon="IconInfo" title="Using PostHog on your frontend too?">
110110

111-
If you're using the PostHog JavaScript Web SDK on your frontend, it generates a session ID for you and you can retrieve it by calling `posthog.get_session_id()`. You then need to pass that session ID to your backend by setting the `X-POSTHOG-SESSION-ID` header on each fetch request. Alternatively, you can enable '__add_tracing_headers' in your config and the header is set automatically.
111+
If you're using the PostHog JavaScript Web SDK on your frontend, it generates a session ID for you.
112+
You can pass it to your backend by adding your backend domain to `__add_tracing_headers` in your config. This will automatically add tracing headers to your requests.
113+
114+
```js
115+
posthog.init('<ph_project_api_key>', {
116+
__add_tracing_headers: ['your-backend-domain.com'] // +
117+
});
118+
```
119+
120+
Alternatively, you can retrieve it on the frontend by calling `posthog.get_session_id()`. You then need to pass that session ID to your backend by setting the `X-POSTHOG-SESSION-ID` header on each fetch request.
112121

113122
You need to extract the header in your request handler (if you're using our Django middleware integration, this happens automatically).
114123

contents/docs/libraries/python/_snippets/django-context-middleware.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ All events captured during the request (including exceptions) will include these
2323

2424
If you are using PostHog on your frontend, the JavaScript Web SDK will add the session and distinct ID headers automatically if you enable tracing headers.
2525

26-
```javascript
27-
__add_tracing_headers: true
26+
```js
27+
posthog.init('<ph_project_api_key>', {
28+
__add_tracing_headers: ['your-backend-domain.com'] // +
29+
})
2830
```
2931

3032
### Exception capture

contents/tutorials/nextjs-error-monitoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ The context of a user and their session lives on the frontend. As such it is nec
244244

245245
```js
246246
posthog.init('<ph_project_api_key>', {
247-
__add_tracing_headers: ['your-domain.com'],
247+
__add_tracing_headers: ['your-backend-domain.com'] // +
248248
})
249249
```
250250

0 commit comments

Comments
 (0)