11import {
22 CustomizationThemeMode ,
3+ type PublishedSiteContent ,
34 SiteInsightsDisplayContext ,
5+ type SiteInsightsEventLocation ,
46 SiteInsightsLLMSVariant ,
57} from '@gitbook/api' ;
68import { isAIAgent } from '@vercel/agent-readability' ;
@@ -441,7 +443,7 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
441443 pathname,
442444 routeType : routeTypeFromPathname ,
443445 events,
444- } = encodePathInSiteContent ( siteURLData . pathname , request ) ;
446+ } = encodePathInSiteContent ( siteURLData , request ) ;
445447 routeType = routeTypeFromPathname ?? routeType ;
446448
447449 if ( events && events . length > 0 ) {
@@ -680,14 +682,23 @@ const PATH_ALIASES: Record<string, string> = {
680682 * Special paths are not encoded and passed to be handled by the route handlers.
681683 */
682684function encodePathInSiteContent (
683- rawPathname : string ,
685+ siteURLData : PublishedSiteContent ,
684686 request : Request
685687) : {
686688 pathname : string ;
687689 routeType ?: 'static' | 'dynamic' ;
688690 events ?: ServerInsightsEventInput [ ] | undefined ;
689691} {
690- let pathname = removeLeadingSlash ( removeTrailingSlash ( rawPathname ) ) ;
692+ let pathname = removeLeadingSlash ( removeTrailingSlash ( siteURLData . pathname ) ) ;
693+
694+ const eventLocation : Partial < SiteInsightsEventLocation > = {
695+ siteSection : siteURLData . siteSection ,
696+ siteSpace : siteURLData . siteSpace ,
697+ siteShareKey : siteURLData . shareKey ,
698+ space : siteURLData . space ,
699+ revision : siteURLData . revision ,
700+ displayContext : SiteInsightsDisplayContext . Server ,
701+ } ;
691702
692703 if ( pathname . match ( / ^ ~ g i t b o o k \/ o g i m a g e \/ \S + $ / ) ) {
693704 return { pathname } ;
@@ -702,9 +713,7 @@ function encodePathInSiteContent(
702713 events : [
703714 {
704715 type : 'rss_request' ,
705- location : {
706- displayContext : SiteInsightsDisplayContext . Server ,
707- } ,
716+ location : eventLocation ,
708717 } ,
709718 ] ,
710719 } ;
@@ -720,6 +729,7 @@ function encodePathInSiteContent(
720729 type : 'llms_request' ,
721730 llmsVariant : SiteInsightsLLMSVariant . Full ,
722731 location : {
732+ siteSection : siteURLData . siteSection ,
723733 displayContext : SiteInsightsDisplayContext . Server ,
724734 } ,
725735 } ,
0 commit comments