diff --git a/.changeset/markdown-events-space-attribution.md b/.changeset/markdown-events-space-attribution.md new file mode 100644 index 0000000000..633e1ab7d4 --- /dev/null +++ b/.changeset/markdown-events-space-attribution.md @@ -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. diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts index 8736966f26..1774c83f32 100644 --- a/packages/gitbook/src/middleware.ts +++ b/packages/gitbook/src/middleware.ts @@ -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 = { - 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, }, ], };