Home /

docs

Analytics

Docs Cloud analytics stores usage events for a Docs Cloud project. The docs runtime emits the events; a Docs Cloud project ID tells Cloud which project should own those events; the dashboard reads the stored event stream.

Teams do not need to configure internal Cloud transport or add an onEvent callback for Cloud storage. onEvent is only for sending an additional copy of the same events to a system the team owns.

Project ID Requirement

Cloud analytics requires a Docs Cloud project ID. Without one, Cloud cannot attach events to a workspace or dashboard.

There are two ways to get the ID:

SourceHow the ID is createdWhen to use it
Imported repositoryImport the repository in Docs Cloud. Cloud creates or reuses the project record and shows its project ID in the Analytics dashboard.Normal Docs Cloud projects and managed previews
Custom analytics projectCreate a custom analytics project from the Docs Cloud Analytics dashboard. Cloud returns an analytics project ID for that source.A docs site that is not tied to a GitHub import yet

Managed Docs Cloud deploys provide the project ID to the runtime for you. For a manually hosted or custom analytics source, copy the project ID from the Docs Cloud Analytics dashboard and set it in the runtime environment:

.env.local
PUBLIC_DOCS_CLOUD_PROJECT_ID=docs_cloud_project_id
# Use DOCS_CLOUD_PROJECT_ID instead when only the server runtime needs the id.
# Next.js projects can use NEXT_PUBLIC_DOCS_CLOUD_PROJECT_ID.

Keep using the dashboard-provided ID. Do not invent one locally; the ID must match an imported repository project or a custom analytics project in Docs Cloud.

The project ID is enough to turn on the built-in Cloud delivery path. To opt out from a manual runtime environment, set the analytics flag to false:

.env.local
NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENABLED=false

Only set NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_ENDPOINT when the docs app should send events to a custom or self-hosted Docs Cloud API. The hosted Docs Cloud endpoint is the default.

If your Cloud workspace issues a dedicated analytics key, set NEXT_PUBLIC_DOCS_CLOUD_ANALYTICS_KEY for browser delivery or DOCS_CLOUD_ANALYTICS_KEY for server-only delivery. The project ID is still required; the key only authenticates the event write.

Runtime Contract

The runtime analytics stream is produced by @farming-labs/docs. Events cover product usage such as page views, search, Ask AI, feedback, page actions, markdown reads, agent reads, and MCP usage.

For a connected Cloud project:

  1. Docs Cloud creates or provides the project ID
  2. the runtime receives that project ID
  3. the runtime enables the built-in Cloud delivery path
  4. Docs Cloud validates the project ID and analytics state
  5. Docs Cloud stores accepted events
  6. the dashboard reads stored events for counts, filters, and recent activity

The public contract is the Docs Cloud project ID, the runtime analytics configuration, and the cloud.analytics setting. The internal transport is managed by Docs Cloud.

Configuration

For frameworkless projects, cloud.analytics can be stored in docs.json because it only contains JSON-safe options:

docs.json
{
  "cloud": {
    "analytics": {
      "enabled": true,
      "console": "info",
      "includeInputs": false
    }
  }
}
OptionMeaning
enabledEnables or disables Cloud analytics for the project
consoleControls runtime console logging for analytics events
includeInputsAllows raw user-authored inputs to be included in analytics events

Function callbacks do not belong in docs.json. If a project needs executable analytics logic, keep that logic in docs.config.ts.

Custom onEvent

Use analytics.onEvent when the project needs a second destination for analytics events:

docs.config.ts
import { defineDocs } from "@farming-labs/docs";

export default defineDocs({
  analytics: {
    async onEvent(event) {
      await sendToCompanyAnalytics(event);
    },
  },
});

For connected Cloud projects, this callback is additive. Docs Cloud still stores its copy of the event through the managed Cloud path.

Privacy Defaults

By default, raw user-authored text is excluded from analytics events. That includes search queries, Ask AI questions, feedback comments, and copied content.

Set includeInputs: true only when the project has the right consent, retention, and review policy for user-authored text:

docs.config.ts
export default defineDocs({
  analytics: {
    includeInputs: true,
  },
});

Stored Event Shape

Docs Cloud stores event fields that are useful for dashboard queries:

Field groupExamples
Project identityproject ID, optional analytics project ID
Event shapetype, source, timestamp
Page contextURL, path, referrer, locale
Optional payloadsinput, properties
Agent traffic hintstrafficType, agentName, botProvider when Cloud can infer an agent or bot source
Timingevent time, received time

The dashboard can use those fields for totals, recent event lists, source filters, event type filters, repository filters, and activity charts.

Agent-readable routes and MCP events are marked as agent traffic when the runtime can infer that from the event source, event type, explicit properties, or known AI crawler user agents. That lets the dashboard separate human docs usage from ChatGPT, Codex, Copilot, Claude, MCP clients, and crawler activity without requiring a custom onEvent callback.

Failure Behavior

Analytics delivery should not break the docs runtime. If Cloud analytics delivery fails, rendering, search, Ask AI, MCP, and a customer-owned onEvent callback should continue independently.

That behavior keeps analytics operationally useful without making analytics availability part of the critical path for serving docs.

Customize
Live preview on these docs
Reset
Customize
Export Code
Preset
Explore more themes
Primary Color
Primary
Colors
Background
Foreground
Muted Text
Border
Card
Muted BG
Ring
Layout
SidebarBordered
TOC StyleDirectional (tree)
TOC DepthH2 + H3
Ask AI
ModeFloating
Floating StyleFull Modal
PositionBottom Right
Features