Home /

docs

Analytics

Use analytics when you want to understand how people and agents use your docs. It emits product-level usage events: page views, search activity, Ask AI requests, feedback, page actions, machine-readable markdown reads, agent feedback routes, and MCP requests.

Analytics is intentionally separate from Observability. Analytics answers "what did users or agents do?" Observability answers "what happened inside this agent run?"

Sending events to Docs Cloud

This page covers the runtime event stream and optional custom destinations. Connected Docs Cloud projects send events to Cloud automatically, store them in Cloud, and show activity in the dashboard. For the Cloud-specific contract, see Docs Cloud Analytics.

Quick Start

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

analytics: true logs usage events to the console with the [@farming-labs/docs:analytics] prefix.

Send Events To Another Tool

For connected Docs Cloud projects, this callback is optional and additive. Use it when you want a copy of events outside Docs Cloud; you do not need it for Cloud storage.

docs.config.ts
export default defineDocs({
  analytics: {
    async onEvent(event) {
      await fetch("https://analytics.example.com/events", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(event),
      });
    },
  },
});

The callback receives a normalized DocsAnalyticsEvent:

interface DocsAnalyticsEvent {
  type: string;
  timestamp: string;
  source: "client" | "server" | "mcp";
  url?: string;
  path?: string;
  referrer?: string;
  locale?: string;
  input?: {
    query?: string;
    question?: string;
    feedbackValue?: string;
    feedbackComment?: string;
    feedbackContext?: Record<string, unknown>;
    feedbackPayload?: Record<string, unknown>;
    agentFeedbackContext?: Record<string, unknown>;
    agentFeedbackPayload?: Record<string, unknown>;
    content?: string;
  };
  metadata?: Record<string, unknown>;
  properties?: Record<string, unknown>;
}

properties carries safe operational details such as status, durations, result counts, model ids, provider names, message counts, content lengths, and route or delivery metadata. Raw user-authored text stays in input and is excluded unless includeInputs: true is set.

Event Types

Analytics events describe product usage: what a person or agent did, which surface they used, and whether the action completed.

Client Events

EventMeaning
page_viewA docs page was viewed in the browser.
search_openThe search UI was opened.
search_closeThe search UI was closed.
search_queryA search query was submitted or changed enough to run search.
search_result_clickA search result was selected.
search_errorClient-side search failed.
ai_openThe Ask AI UI was opened.
ai_closeThe Ask AI UI was closed.
ai_questionA user submitted a question to Ask AI from the client UI.
ai_responseThe Ask AI UI received a successful response.
ai_feedbackA user rated a completed Ask AI answer with the response feedback buttons.
ai_errorThe Ask AI UI encountered an error.
ai_clearThe Ask AI conversation was cleared.
page_action_copy_markdownThe Copy Markdown page action was used.
page_action_open_docs_menuThe Open in LLM/Open docs page-action menu was opened.
page_action_open_docsA destination in the Open in LLM/Open docs menu was selected.
code_block_copyA code block copy button was clicked.
feedback_selectA feedback rating or option was selected.
feedback_submitFeedback was submitted successfully.
feedback_errorFeedback submission failed.

Server And Agent-Surface Events

EventMeaning
api_searchThe docs API handled a search request.
api_ai_requestThe docs API accepted an Ask AI request.
api_ai_responseThe docs API returned a successful Ask AI response.
api_ai_errorThe docs API rejected or failed an Ask AI request.
agent_readA page was read through a machine-readable docs surface.
agents_requestAn agent-facing generated instruction file was requested.
markdown_requestA markdown route or API markdown request was served.
llms_request/llms.txt or /llms-full.txt was requested.
skill_requestAn Agent Skills file or skill index was requested.
agent_spec_requestThe agent-facing docs spec endpoint was requested.
agent_feedback_schemaThe agent feedback schema endpoint was requested.
agent_feedback_submitAgent feedback was submitted successfully.
agent_feedback_errorAgent feedback submission failed.
mcp_requestThe MCP endpoint received a request.
mcp_toolAn MCP tool call was handled, such as search_docs or read_page.

agent_read includes properties.delivery so you can see how the page was read: md_route, accept_header, signature_agent, user_agent, heuristic, api_format, or mcp_tool.

Ask AI API events include the provider, model, message count, question length, status or error reason, and durationMs when available. When ai.provider is "docs-cloud", those events identify the provider as docs-cloud even if the request is served through the local docs API proxy.

Input Privacy

By default, analytics events include safe metadata such as paths, counts, durations, status, result counts, model IDs, content lengths, and whether a comment exists.

Inputs are excluded by default

Search queries, AI questions, feedback comments, and copied content are not included unless you explicitly set includeInputs: true.

Enable raw input capture only when you have user consent and a retention policy:

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

Options

OptionTypeDefault
enabledbooleantrue when object is passed
consoleboolean | "log" | "info" | "debug"true for analytics: true
includeInputsbooleanfalse
onEvent(event) => void | Promise<void>undefined

Configure both streams when you want usage analytics and runtime traces:

docs.config.ts
export default defineDocs({
  analytics: {
    onEvent: sendUsageEvent,
  },
  observability: {
    console: "debug",
    onEvent: sendTraceEvent,
  },
});
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