> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/developers/gitbook-api/api-reference/docs-sites/site-insights/query-a-sites-analytics-events.md).

# Query a site's analytics events

Runs an aggregation query over a published site's Insights events, grouped and filtered over a time range. Use it to answer analytics questions about how visitors engage with a site's documentation: page views, visitors, searches, referrers, and broken URLs (404s). A 404 is a `page_view` or `search_open_result` event whose `page` is `null`, in the `site` display context; filter `eventPageNotFoundType` not in `conditional` to leave out 404s that adaptive content explains. Group by `datetime` for a trend over time and by `urlPath` for the top broken URLs.

```json
{"openapi":"3.1.0","info":{"title":"GitBook API","version":"0.0.1-beta"},"tags":[{"name":"site-insights","description":"This API delivers insights about how visitors interact with your site, including page views and user engagement, helping you measure and optimize your content strategy.\n"}],"servers":[{"url":"{host}/v1","variables":{"host":{"default":"https://api.gitbook.com"}}}],"security":[{"user":[]},{"oauth":["site:insights:read"]}],"components":{"securitySchemes":{"user":{"type":"http","scheme":"bearer"},"oauth":{"type":"oauth2","flows":{"authorizationCode":{"authorizationUrl":"https://oauth.gitbook.com/authorize","tokenUrl":"https://oauth.gitbook.com/token","scopes":{"user:read":"Read your GitBook user profile.","organization:read":"Read the organizations you belong to, their settings and metadata, and their AI agent conversations.","organization:write":"Create organizations, and update organization settings and AI agent conversations.","organization:members:read":"Read organization members, teams, invites and link invites.","organization:members:write":"Manage organization members, teams, invites and link invites.","organization:ask":"Ask AI questions across an organization's content.","organization:search":"Search across an organization's content.","space:read":"Read spaces and their content, including pages, change requests and their reviews, comments, files and revision history.","space:write":"Create, update and delete spaces and their content, including change requests (create, edit, review), comments, and content imports and exports. Merging a change request also requires change-request:merge.","space:permissions:read":"Read the users and teams who have access to spaces and collections.","space:permissions:write":"Manage who has access to spaces and collections, including inviting users and teams.","change-request:merge":"Merge change requests, publishing their changes to the space. Creating, editing and reviewing change requests only requires space:write.","site:read":"Read sites and their settings, including navigation structure, linked spaces, customization, redirects, topics, AI configuration and documentation issues.","site:write":"Create, update and delete sites and their settings, including navigation structure (sections, linked spaces, external links), customization, redirects, topics and AI configuration.","site:publish":"Publish and unpublish sites, controlling their public exposure.","site:permissions:read":"Read the users and teams who have access to sites.","site:permissions:write":"Manage who has access to sites, including inviting users and teams.","site:auth:read":"Read how visitors authenticate on a site and its security configuration, including private share links.","site:auth:write":"Manage how visitors authenticate on a site and its security configuration, including private share links.","site:insights:read":"Read site analytics and insights, including the questions visitors asked Ask AI and the answers they received.","site:ask":"Ask AI questions across a site's content.","site:search":"Search across a site's content.","integration:read":"Read integrations, their status and where they are installed.","integration:installations:read":"Read integration installations and their configuration, which can include credentials for third-party services.","integration:installations:write":"Install and configure integrations on an organization, its spaces and its sites.","integration:publish":"Publish integrations, which can request their own permissions on your content, and route their events to a development tunnel.","integration:delete":"Unpublish integrations, permanently deleting them and every installation of them.","openapi:read":"Read OpenAPI specifications.","openapi:write":"Create, update and delete OpenAPI specifications."}}}}},"parameters":{"organizationId":{"name":"organizationId","in":"path","required":true,"description":"The unique id of the organization","schema":{"$ref":"#/components/schemas/EntityId"}},"siteId":{"name":"siteId","in":"path","required":true,"description":"The unique id of the site","schema":{"type":"string"}}},"schemas":{"EntityId":{"type":"string","pattern":"^[a-zA-Z0-9_-]+$","description":"A unique entity identifier"},"SiteInsightsQueryEventsAggregation":{"type":"object","required":["range"],"properties":{"select":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsQueryEventsColumn"}},"where":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsQueryEventsFilter"}},"groupBy":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsQueryEventsColumn"}},"order":{"type":"object","required":["by","direction"],"properties":{"by":{"$ref":"#/components/schemas/SiteInsightsQueryEventsColumn"},"direction":{"type":"string","enum":["asc","desc"]}}},"range":{"$ref":"#/components/schemas/SiteInsightsQueryRange"},"limit":{"type":"integer","default":1000,"minimum":1,"maximum":1000}}},"SiteInsightsQueryEventsColumn":{"oneOf":[{"$ref":"#/components/schemas/SiteInsightsQueryDateTimeColumn"},{"type":"object","description":"Day of the week the event happened, in UTC, from 1 (Monday) to 7 (Sunday). Group by it alongside `hourOfDay` to fold any range into a weekly activity profile.","required":["column"],"properties":{"column":{"type":"string","enum":["dayOfWeek"]}}},{"type":"object","description":"Hour of the day the event happened, in UTC, from 0 to 23.","required":["column"],"properties":{"column":{"type":"string","enum":["hourOfDay"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["url"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["urlPath"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventType"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventsCount"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["sessionsCount"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorsCount"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["siteSection"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["siteSpace"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["siteShareKey"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["displayContext"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["page"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorGeoCountry"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorGeoPoint"]},"precision":{"type":"integer","minimum":0,"maximum":15}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorDevice"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorBrowser"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorOS"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorBot"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorLanguage"]}}},{"type":"object","description":"The raw `User-Agent` header of the request. `visitorBot`, `visitorBrowser`, `visitorOS` and `visitorDevice` are parsed from it.","required":["column"],"properties":{"column":{"type":"string","enum":["visitorUserAgent"]}}},{"type":"object","description":"Pseudonymous identifier of the visitor, stable across a browser's visits. Events served by the server (`displayContext` of `server` or `mcp`: markdown pages, llms.txt, RSS, MCP) get a new one per request, so it only tells visitors apart on `site` and `embed`.","required":["column"],"properties":{"column":{"type":"string","enum":["visitorId"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventLinkTargetValue"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventLinkTargetKind"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventLinkTargetDomain"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventLinkPosition"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventAPIOperationPath"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventAPIOperationMethod"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventLLMSVariant"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventPageNotFoundType"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventMarkdownSource"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventSearchQuery"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventSearchResultRecordId"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventPageFeedbackRating"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventPageFeedbackComment"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventAskResponseRating"]}}},{"type":"object","description":"How a page was rated, counted once per rating a reader submitted rather than once per\nevent: rating a page and then commenting on it records two events carrying the same\nrating, and a reader may rate a page again on a later visit.\n","required":["column"],"properties":{"column":{"type":"string","enum":["pageFeedbackRating"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["askResponseRating"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["referrer"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["referrerDomain"]}}},{"type":"object","description":"Path of the page of the site the visitor was on before the event, without the origin, share-link prefix, query string or fragment. Empty when the visitor came from another origin, or for events tracked before it was recorded.","required":["column"],"properties":{"column":{"type":"string","enum":["previousUrl"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["utmSource"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["utmMedium"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["utmCampaign"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["utmTerm"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["utmContent"]}}},{"type":"object","description":"Whether the visitor was authenticated when the event happened. Recorded at ingest from the site's visibility and the visitor's claims, so it is only exact for events tracked after that became available; older events fall back to the presence of any claim.","required":["column"],"properties":{"column":{"type":"string","enum":["visitorAuthenticated"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["visitorClaimProperty"]}}},{"type":"object","required":["column","claim"],"properties":{"column":{"type":"string","enum":["visitorClaim"]},"claim":{"type":"string"}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventAdDomain"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventAdPlacement"]}}},{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["eventTrademarkPlacement"]}}}]},"SiteInsightsQueryDateTimeColumn":{"type":"object","required":["column"],"properties":{"column":{"type":"string","enum":["datetime"]},"interval":{"type":"string","enum":["hour","day","week","month"]}}},"SiteInsightsQueryEventsFilter":{"allOf":[{"$ref":"#/components/schemas/SiteInsightsQueryEventsValues"},{"type":"object","properties":{"operator":{"$ref":"#/components/schemas/SiteInsightsQueryOperator"}}}]},"SiteInsightsQueryEventsValues":{"oneOf":[{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["datetime"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/Timestamp"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["dayOfWeek"]},"values":{"type":"array","items":{"type":"integer","minimum":1,"maximum":7}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["hourOfDay"]},"values":{"type":"array","items":{"type":"integer","minimum":0,"maximum":23}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["url"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/URL"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["urlPath"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventsCount"]},"values":{"type":"array","items":{"type":"number"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["sessionsCount"]},"values":{"type":"array","items":{"type":"number"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorsCount"]},"values":{"type":"array","items":{"type":"number"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventType"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsEventType"}}}},{"type":"object","required":["column","claim","values"],"properties":{"column":{"type":"string","enum":["visitorClaim"]},"claim":{"type":"string"},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorAuthenticated"]},"values":{"type":"array","items":{"type":["boolean","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorClaimProperty"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorBrowser"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsVisitorBrowser"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorDevice"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsVisitorDevice"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorOS"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsVisitorOS"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorBot"]},"values":{"type":"array","items":{"oneOf":[{"$ref":"#/components/schemas/SiteInsightsVisitorBot"},{"type":"string","enum":[""]}]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventLinkTargetValue"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/ContentRef"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventLinkTargetKind"]},"values":{"type":"array","items":{"type":"string","enum":["url","page","file","anchor","space","collection","user","reusable-content"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventLinkPosition"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsLinkPosition"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["siteSection"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventLLMSVariant"]},"values":{"type":"array","items":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/SiteInsightsLLMSVariant"}]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventPageNotFoundType"]},"values":{"type":"array","items":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/SiteInsightsPageNotFoundType"}]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventMarkdownSource"]},"values":{"type":"array","items":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/SiteInsightsMarkdownSource"}]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["siteSpace"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["siteShareKey"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["displayContext"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsDisplayContext"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["page"]},"values":{"description":"Pages to match. `null` matches events that resolved to no page, which for `page_view` events is a 404 (a broken URL).","type":"array","items":{"oneOf":[{"type":"null"},{"type":"object","required":["page","space"],"properties":{"page":{"type":["string","null"]},"space":{"type":"string"}}}]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorGeoCountry"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorGeoPoint"]},"values":{"type":"array","items":{"type":["object","null"],"required":["latitude","longitude","h3"],"properties":{"latitude":{"type":"number"},"longitude":{"type":"number"},"h3":{"type":"string"}}}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorLanguage"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorUserAgent"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["visitorId"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventLinkTargetDomain"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventAPIOperationPath"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventAPIOperationMethod"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventSearchQuery"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventSearchResultRecordId"]},"values":{"type":"array","items":{"type":["string","null"]}}}},{"type":"object","description":"Ratings submitted on a page, counted once per rating a reader submitted rather than once\nper event.\n","required":["column","values"],"properties":{"column":{"type":"string","enum":["pageFeedbackRating"]},"values":{"type":"array","items":{"type":"object","required":["ok","good","bad"],"properties":{"ok":{"type":"number"},"good":{"type":"number"},"bad":{"type":"number"}}}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["askResponseRating"]},"values":{"type":"array","items":{"type":"object","required":["positive","negative"],"properties":{"positive":{"type":"number"},"negative":{"type":"number"}}}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventPageFeedbackRating"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/PageFeedbackRating"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventAskResponseRating"]},"values":{"type":"array","items":{"type":"integer"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventPageFeedbackComment"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["referrer"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["referrerDomain"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["previousUrl"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["utmSource"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["utmMedium"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["utmCampaign"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["utmTerm"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["utmContent"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventAdDomain"]},"values":{"type":"array","items":{"type":"string"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventAdPlacement"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsAdPlacement"}}}},{"type":"object","required":["column","values"],"properties":{"column":{"type":"string","enum":["eventTrademarkPlacement"]},"values":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsTrademarkPlacement"}}}}]},"Timestamp":{"type":"string","format":"date-time"},"URL":{"type":"string","format":"uri","maxLength":2048},"SiteInsightsEventType":{"type":"string","enum":["page_view","page_markdown_request","search_open","search_type_query","search_open_result","page_post_feedback","page_post_feedback_comment","agent_feedback","ask_question","ask_view","ask_trigger_click","ask_rate_response","link_click","api_client_open","api_client_request","ad_click","ad_display","trademark_click","llms_request","mcp_request","rss_request"]},"SiteInsightsVisitorBrowser":{"type":"string","enum":["chrome","firefox","safari","edge","ie","opera","unknown"]},"SiteInsightsVisitorDevice":{"type":"string","enum":["desktop","tablet","mobile","unknown"]},"SiteInsightsVisitorOS":{"type":"string","enum":["windows","macos","linux","android","ios","unknown"]},"SiteInsightsVisitorBot":{"type":["string","null"],"enum":[null,"unknown","googlebot","bingbot","duckduckbot","facebookbot","applebot","chatgpt","openai","claude","anthropic","gemini","perplexity","cohere","mistral","deepseek","meta","bytespider","ccbot","amazonbot","youbot","cursor","vscode","claude-code","codex","opencode","gptbot","claudebot","meta-fetcher","grok","github-copilot","meta-webindexer","meta-ads","duckassist","amzn-searchbot","amzn-user","other-bot","parallel","exa","linkup","vertex-ai","atlassian","kapa","bedrock"]},"ContentRef":{"description":"A relative reference to content in GitBook.","oneOf":[{"$ref":"#/components/schemas/ContentRefFile"},{"$ref":"#/components/schemas/ContentRefURL"},{"$ref":"#/components/schemas/ContentRefPage"},{"$ref":"#/components/schemas/ContentRefAnchor"},{"$ref":"#/components/schemas/ContentRefUser"},{"$ref":"#/components/schemas/ContentRefCollection"},{"$ref":"#/components/schemas/ContentRefSpace"},{"$ref":"#/components/schemas/ContentRefReusableContent"},{"$ref":"#/components/schemas/ContentRefTag"},{"$ref":"#/components/schemas/ContentRefOpenAPI"}]},"ContentRefFile":{"type":"object","properties":{"kind":{"type":"string","enum":["file"]},"file":{"type":"string"},"space":{"description":"ID of the space the file is in. The file is considered as in the current space if none is provided.","type":"string"}},"required":["kind","file"]},"ContentRefURL":{"type":"object","properties":{"kind":{"type":"string","enum":["url"]},"url":{"type":"string"}},"required":["kind","url"]},"ContentRefPage":{"type":"object","properties":{"kind":{"type":"string","enum":["page"]},"page":{"type":"string"},"space":{"description":"ID of the space the page is in. The page is considered as in the current space if none is provided.","type":"string"}},"required":["kind","page"]},"ContentRefAnchor":{"type":"object","properties":{"kind":{"type":"string","enum":["anchor"]},"anchor":{"type":"string"},"space":{"description":"ID of the space the page is in. The page is considered as in the current space if none is provided.","type":"string"},"page":{"description":"ID of the page the anchor is in. The anchor is considered as in the current page if none is provided.","type":"string"}},"required":["kind","anchor"]},"ContentRefUser":{"type":"object","properties":{"kind":{"type":"string","enum":["user"]},"user":{"type":"string"}},"required":["kind","user"]},"ContentRefCollection":{"type":"object","properties":{"kind":{"type":"string","enum":["collection"]},"collection":{"type":"string"}},"required":["kind","collection"]},"ContentRefSpace":{"type":"object","properties":{"kind":{"type":"string","enum":["space"]},"space":{"type":"string"}},"required":["kind","space"]},"ContentRefReusableContent":{"type":"object","properties":{"kind":{"type":"string","enum":["reusable-content"]},"reusableContent":{"type":"string"},"space":{"type":"string","description":"The space in which the reusable content is defined. If undefined, the reusable content is assumed to be in the same space as the content reference."}},"required":["kind","reusableContent"]},"ContentRefTag":{"type":"object","properties":{"kind":{"type":"string","enum":["tag"]},"tag":{"type":"string","description":"The slug of the tag, also used as the ID, and references the tags defined on a revision."},"space":{"type":"string","description":"The space in which the tag is defined. If undefined, the tag is assumed to be in the same space as the content reference."}},"required":["kind","tag"]},"ContentRefOpenAPI":{"type":"object","properties":{"kind":{"type":"string","enum":["openapi"]},"spec":{"type":"string","description":"Slug of the OpenAPI specification"}},"required":["kind","spec"]},"SiteInsightsLinkPosition":{"type":"string","enum":["announcement","header","footer","sidebar","content"]},"SiteInsightsLLMSVariant":{"type":"string","enum":["standard","full"]},"SiteInsightsPageNotFoundType":{"description":"Why a site URL returned a 404. `conditional` means the URL targets content gated by an adaptive-content condition, so the visitor lacked access to a page that exists. Computed by GitBook when the event is ingested; 404s recorded before this existed, and those on genuinely missing pages, carry no value.","type":"string","enum":["conditional"]},"SiteInsightsMarkdownSource":{"description":"How a page's markdown was requested. `page-action` means a reader used the site's page-actions menu — its copy or view-as-markdown action — rather than a client fetching the URL directly.","type":"string","enum":["page-action"]},"SiteInsightsDisplayContext":{"type":"string","description":"Context in which the event was recorded.","enum":["site","server","embed","mcp"]},"PageFeedbackRating":{"type":"string","enum":["bad","ok","good"]},"SiteInsightsAdPlacement":{"type":"string","enum":["aside"]},"SiteInsightsTrademarkPlacement":{"type":"string","enum":["sidebar","ad","footer","pdf","embed"]},"SiteInsightsQueryOperator":{"type":"string","enum":["in","notIn","greaterThan","greaterThanOrEqual","lessThan","lessThanOrEqual"]},"SiteInsightsQueryRange":{"oneOf":[{"$ref":"#/components/schemas/SiteInsightsQueryRangePreset"},{"$ref":"#/components/schemas/SiteInsightsQueryRangeCustom"}]},"SiteInsightsQueryRangePreset":{"type":"string","enum":["yearToDate","lastYear","last3Months","last30Days","last7Days","last24Hours"]},"SiteInsightsQueryRangeCustom":{"type":"object","properties":{"from":{"$ref":"#/components/schemas/Timestamp"},"to":{"$ref":"#/components/schemas/Timestamp"}},"required":["from","to"]},"SiteInsightsQueryEventsAggregationResult":{"type":"object","required":["columns"],"properties":{"columns":{"type":"array","items":{"$ref":"#/components/schemas/SiteInsightsQueryEventsValues"}}}}}},"paths":{"/orgs/{organizationId}/sites/{siteId}/insights/events/aggregate":{"post":{"operationId":"aggregateSiteEvents","summary":"Query a site's analytics events","description":"Runs an aggregation query over a published site's Insights events, grouped and filtered over a time range. Use it to answer analytics questions about how visitors engage with a site's documentation: page views, visitors, searches, referrers, and broken URLs (404s). A 404 is a `page_view` or `search_open_result` event whose `page` is `null`, in the `site` display context; filter `eventPageNotFoundType` not in `conditional` to leave out 404s that adaptive content explains. Group by `datetime` for a trend over time and by `urlPath` for the top broken URLs.","tags":["site-insights"],"parameters":[{"$ref":"#/components/parameters/organizationId"},{"$ref":"#/components/parameters/siteId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SiteInsightsQueryEventsAggregation"}}}},"responses":{"200":{"description":"Aggregated events in the site.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SiteInsightsQueryEventsAggregationResult"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/developers/gitbook-api/api-reference/docs-sites/site-insights/query-a-sites-analytics-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
