Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/markdown-events-space-attribution.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 8 additions & 11 deletions packages/gitbook/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
},
],
};
Expand Down
Loading