Compare commits

...

2 Commits

Author SHA1 Message Date
Nolann Biron 1cfc0c1f99 changeset 2026-08-14 14:32:43 +02:00
Nolann Biron 6ca03e53b4 Attribute markdown and ask events to their space
`page_markdown_request` and the `ask_question` the middleware emits for `?ask=`
carried only a displayContext, so they were stored with an empty spaceId and an
unparseable siteSpaceId. Any space- or section-scoped query dropped them, and the
markdown traffic of a space read as zero.

Reuse the location the middleware already builds, as `rss_request` does. The
llms branches keep theirs: llms.txt spans every section and site-space, so a
single spaceId would attribute a site-wide document to one of them.

`ask_question` also gains the goal, which was parsed off the query string to be
encoded in the rewrite and then dropped from the event.

The pageId the TODO asked for is not in the URL, and resolving it in the
middleware costs a request per document served; it is left to the API to return
alongside the space.
2026-08-14 14:32:36 +02:00
2 changed files with 13 additions and 11 deletions
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Attribute the markdown and ask events tracked from the middleware to their space, and record the goal passed alongside a question.
+8 -11
View File
@@ -753,12 +753,14 @@ function encodePathInSiteContent(
} {
let pathname = removeLeadingSlash(removeTrailingSlash(siteURLData.pathname));
// The optional fields are coerced to null, otherwise they are dropped from the JSON payload
// instead of being sent as the `string | null` the API expects.
const eventLocation: Partial<SiteInsightsEventLocation> = {
siteSection: siteURLData.siteSection,
siteSection: siteURLData.siteSection ?? null,
siteSpace: siteURLData.siteSpace,
siteShareKey: siteURLData.shareKey,
siteShareKey: siteURLData.shareKey ?? null,
space: siteURLData.space,
revision: siteURLData.revision,
revision: siteURLData.revision ?? null,
displayContext: SiteInsightsDisplayContext.Server,
};
@@ -881,24 +883,19 @@ function encodePathInSiteContent(
}`
: `~gitbook/markdown/${encodePagePath(pagePathWithoutMD)}`,
routeType: 'static',
// TODO: track pageId / spaceId when possible
// We don't do it at the moment as we can't easily extract it from the URL.
events: ask
? [
{
type: 'ask_question',
query: ask,
location: {
displayContext: SiteInsightsDisplayContext.Server,
},
...(goal ? { goal } : {}),
location: eventLocation,
},
]
: [
{
type: 'page_markdown_request',
location: {
displayContext: SiteInsightsDisplayContext.Server,
},
location: eventLocation,
},
],
};