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?"

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 Your Own Sink

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;
    feedbackComment?: string;
    content?: string;
  };
  metadata?: Record<string, unknown>;
  properties?: Record<string, unknown>;
}

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.
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, api_format, or mcp_tool.

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,
  },
});