07 / 08

API and MCP access

Query everything in the dashboard from agents over REST or MCP, with fetch examples.

Authentication

Everything in the dashboard is queryable over a small REST API at https://api.motion.dev/analytics/v1. It returns compact JSON with explicit units and ISO dates, designed for agents as much as for scripts. Every request needs a Bearer token from your sites dashboard: add the tracker to a site, register it, and create a token. Tokens are scoped to exactly your sites and rate limited to 600 queries an hour.

Responses carry an estimated flag, which is true whenever per-site sampling was in play at very high volume, so a script never presents an estimate as exact.

Endpoints

Every endpoint takes range as day, week, month (the default) or quarter.

MethodEndpointReturns
GET/sitesYour registered sites
GET/statsTotals, live, timeseries, breakdowns and events
GET/pagesTop pages; group=true collates by first segment
GET/performanceField performance grades, slowest first
GET/compareRange-over-range totals with precomputed deltas
GET/funnelsYour funnels with step counts
POST/funnelsCreate a funnel
GET/funnels/:idOne funnel's step counts
DELETE/funnels/:idDelete a funnel

Pass a token as a header and read JSON back. Listing your sites:

const res = await fetch("https://api.motion.dev/analytics/v1/sites", {
  headers: { Authorization: "Bearer mat_..." },
})
const { sites } = await res.json()

Stats take a site and optional filters (path, ref, country, device, browser, os and the five utm_* values), each scoping every number in the response.

const res = await fetch(
  "https://api.motion.dev/analytics/v1/stats?site=example.com&range=week",
  { headers: { Authorization: "Bearer mat_..." } },
)
const data = await res.json()
// data.totals.visitors, data.timeseries, data.breakdowns.country, data.events
// data.estimated is true when sampling was in play — never quote it as exact.

Funnels are created with an ordered list of steps, each a page path (wildcards allowed, e.g. /docs/*) or a custom event name.

await fetch("https://api.motion.dev/analytics/v1/funnels", {
  method: "POST",
  headers: {
    Authorization: "Bearer mat_...",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    site: "example.com",
    name: "Signup",
    steps: [
      { type: "page", value: "/pricing" },
      { type: "event", value: "Signed up" },
    ],
  }),
})

MCP access

For MCP clients (Claude Code, Cursor and friends), point at the remote endpoint with the same Bearer token. Claude Code:

claude mcp add --transport http motion-analytics \
  https://api.motion.dev/analytics/mcp \
  --header "Authorization: Bearer mat_..."

The server exposes analytics-list-sites, analytics-stats, analytics-top-pages, analytics-performance, analytics-compare, analytics-incidents, analytics-funnel, analytics-create-funnel and analytics-delete-funnel. Or copy a setup prompt for your agent: