{"components":{"parameters":{"FilterBrowser":{"description":"Exact value from the `browser` breakdown.","example":"Chrome","in":"query","name":"f.browser","schema":{"type":"string"}},"FilterCountry":{"description":"ISO 3166-1 alpha-2 country code, `(none)` for unknown.","example":"CH","in":"query","name":"f.country","schema":{"type":"string"}},"FilterDevice":{"description":"Device class.","in":"query","name":"f.device","schema":{"enum":["Desktop","Tablet","Mobile"],"type":"string"}},"FilterEntryPage":{"description":"Exact pathname of the visit's first page.","in":"query","name":"f.entry_page","schema":{"type":"string"}},"FilterEvent":{"description":"Custom event name; only visits that fired it.","example":"signup","in":"query","name":"f.event","schema":{"type":"string"}},"FilterOs":{"description":"Exact value from the `os` breakdown.","example":"macOS","in":"query","name":"f.os","schema":{"type":"string"}},"FilterPage":{"description":"Only visits that viewed this exact pathname (`breakdown?property=page` counts only this page).","example":"/preise","in":"query","name":"f.page","schema":{"type":"string"}},"FilterSource":{"description":"Referrer source as in the `source` breakdown, `Direct / None` for visits without one.","example":"Google","in":"query","name":"f.source","schema":{"type":"string"}},"FilterUtmCampaign":{"description":"Exact `utm_campaign`, `(none)` for visits without one.","in":"query","name":"f.utm_campaign","schema":{"type":"string"}},"FilterUtmMedium":{"description":"Exact `utm_medium`, `(none)` for visits without one.","in":"query","name":"f.utm_medium","schema":{"type":"string"}},"FilterUtmSource":{"description":"Exact `utm_source`, `(none)` for visits without one.","in":"query","name":"f.utm_source","schema":{"type":"string"}},"From":{"description":"First day of a `custom` period (inclusive), in the site's time zone.","example":"2026-11-01","in":"query","name":"from","schema":{"format":"date","type":"string"}},"Period":{"description":"`today` (default), `yesterday`, `7d` and `30d` (ending today, today included), `month`\n(this month), `last_month`, `12m` (the last twelve months by month), `custom` (needs\n`from` and `to`).\n","in":"query","name":"period","schema":{"$ref":"#/components/schemas/Period"}},"SiteId":{"description":"Numeric site id (see `GET /api/v1/sites`).","example":3,"in":"path","name":"id","required":true,"schema":{"format":"int64","type":"integer"}},"To":{"description":"Last day of a `custom` period (inclusive). At most 731 days after `from`.","example":"2026-11-21","in":"query","name":"to","schema":{"format":"date","type":"string"}}},"responses":{"BadRequest":{"content":{"application/json":{"example":{"error":"bad_request","message":"unknown period 3d"},"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Malformed input, e.g. an unknown period, filter or property, or a bad date range."},"NotFound":{"content":{"application/json":{"example":{"error":"not_found","message":"not found"},"schema":{"$ref":"#/components/schemas/Error"}}},"description":"No such site, or a site the key's owner may not see (another organisation's site, a revoked\nshare, or not granted by their teams). All answer the same, so a key cannot find out which\nother sites exist.\n"},"Unauthorized":{"content":{"application/json":{"example":{"error":"unauthorized","message":"login required"},"schema":{"$ref":"#/components/schemas/Error"}}},"description":"Missing, unknown or revoked API key."}},"schemas":{"Aggregate":{"allOf":[{"$ref":"#/components/schemas/Totals"},{"properties":{"previous":{"description":"The same numbers for the period right before: the previous day for\n`today`/`yesterday`, the previous calendar month for `month`/`last_month`, the\nsame number of days before for `7d`, `30d` and `custom`; `null` for `12m`.\n","oneOf":[{"$ref":"#/components/schemas/Totals"},{"type":"null"}]}},"required":["previous"],"type":"object"}]},"Breakdown":{"properties":{"property":{"$ref":"#/components/schemas/BreakdownProperty"},"results":{"items":{"properties":{"count":{"example":140,"type":"integer"},"percentage":{"example":21.4,"type":"number"},"value":{"example":"/preise","type":"string"},"visitors":{"example":88,"type":"integer"}},"required":["value","visitors","count","percentage"],"type":"object"},"type":"array"}},"required":["property","results"],"type":"object"},"BreakdownProperty":{"enum":["page","entry_page","exit_page","source","referrer","utm_source","utm_medium","utm_campaign","country","browser","os","device","event"],"type":"string"},"Config":{"properties":{"public_url":{"example":"https://pegel-api.rigilab.com","format":"uri","type":"string"},"script_url":{"example":"https://pegel-api.rigilab.com/js/pegel.js","format":"uri","type":"string"},"version":{"example":"2026.11.22-abc1234","type":"string"}},"required":["version","public_url","script_url"],"type":"object"},"Error":{"properties":{"error":{"enum":["bad_request","unauthorized","forbidden","not_found","conflict","gone","too_many_requests","internal"],"type":"string"},"message":{"type":"string"}},"required":["error","message"],"type":"object"},"JsonRpcRequest":{"properties":{"id":{"description":"Absent for notifications.","type":["integer","string"]},"jsonrpc":{"const":"2.0","type":"string"},"method":{"enum":["initialize","notifications/initialized","ping","tools/list","tools/call"],"type":"string"},"params":{"description":"For `tools/call`: `{\"name\": \"<tool>\", \"arguments\": {…}}`.","properties":{"arguments":{"additionalProperties":true,"type":"object"},"name":{"enum":["list_sites","get_stats","get_timeseries","get_breakdown","get_realtime"],"type":"string"}},"type":"object"}},"required":["jsonrpc","method"],"type":"object"},"JsonRpcResponse":{"properties":{"error":{"properties":{"code":{"type":"integer"},"message":{"type":"string"}},"required":["code","message"],"type":"object"},"id":{"type":["integer","string","null"]},"jsonrpc":{"const":"2.0","type":"string"},"result":{"additionalProperties":true,"description":"For `tools/call`: `{\"content\": [{\"type\": \"text\", \"text\": \"<json>\"}], \"structuredContent\": {…}, \"isError\": false}`.","type":"object"}},"required":["jsonrpc"],"type":"object"},"Period":{"default":"today","enum":["today","yesterday","7d","30d","month","last_month","12m","custom"],"type":"string"},"Realtime":{"properties":{"pages":{"items":{"properties":{"value":{"example":"/preise","type":"string"},"visitors":{"example":3,"type":"integer"}},"required":["value","visitors"],"type":"object"},"type":"array"},"visitors":{"example":7,"type":"integer"}},"required":["visitors","pages"],"type":"object"},"Site":{"properties":{"created_at":{"format":"date-time","type":"string"},"domain":{"example":"example.com","type":"string"},"group_id":{"description":"The site's group (groups and teams), `null` for none, and also `null` when the group\nbelongs to another organisation and is not shared with the key's.\n","example":2,"format":"int64","type":["integer","null"]},"id":{"example":3,"format":"int64","type":"integer"},"name":{"example":"Example Website","type":"string"},"shared_by":{"description":"Name of the owning organisation when the site is shared with the key's organisation\n(read-only there); `null` for the organisation's own sites.\n","example":null,"type":["string","null"]},"timezone":{"description":"IANA time zone of the site's calendar days.","example":"Europe/Zurich","type":"string"},"visitors_24h":{"description":"Visitors in the rolling last 24 hours.","example":412,"type":"integer"}},"required":["id","domain","name","timezone","created_at","visitors_24h","group_id","shared_by"],"type":"object"},"Timeseries":{"properties":{"interval":{"enum":["hour","day","month"],"type":"string"},"points":{"items":{"properties":{"date":{"description":"`2026-11-22T14:00`, `2026-11-21` or `2026-11`, by interval.","example":"2026-11-21","type":"string"},"pageviews":{"example":480,"type":"integer"},"visitors":{"example":120,"type":"integer"}},"required":["date","visitors","pageviews"],"type":"object"},"type":"array"}},"required":["interval","points"],"type":"object"},"Totals":{"properties":{"bounce_rate":{"description":"Percent of visits with exactly one page view and no custom event.","example":41.5,"type":"number"},"pageviews":{"example":1804,"type":"integer"},"views_per_visit":{"example":3.4,"type":"number"},"visit_duration":{"description":"Mean seconds between the first and last event of a visit.","example":96,"type":"integer"},"visitors":{"description":"Distinct daily visitor ids, summed per day.","example":412,"type":"integer"},"visits":{"description":"Sessions (a session ends after 30 minutes without an event).","example":530,"type":"integer"}},"required":["visitors","visits","pageviews","views_per_visit","bounce_rate","visit_duration"],"type":"object"}},"securitySchemes":{"apiKey":{"bearerFormat":"pgl_… API key","description":"An API key from *API & MCP* in the Pegel app (`pgl_` + 43 characters). A login token\n(JWT) from the app works too.\n","scheme":"bearer","type":"http"}}},"info":{"contact":{"name":"Pegel","url":"https://pegel.rigilab.com"},"description":"Read your Pegel statistics from scripts, dashboards, BI tools (Looker Studio, Grafana,\nExcel) and AI assistants.\n\n## Authentication\n\nCreate an **API key** in the Pegel app under *API & MCP* and send it as a bearer token:\n\n```\nAuthorization: Bearer pgl_…\n```\n\nAPI keys are read-only: they work for every endpoint on this page; anything that changes\ndata answers `403 forbidden`. A key belongs to one organisation (the one it was created in)\nand reads exactly the sites its owner sees there; it dies with its owner or when the owner\nleaves that organisation. The secret is shown once, at creation; the hub stores only its\nSHA-256.\n\n## Access: organisations, sharing, groups and teams\n\nEvery site belongs to an organisation. A key reaches its organisation's own sites plus the\nsites another organisation shares with it, read-only (`shared_by` names the owner; a shared\ngroup also covers sites added to it later). When a share is revoked, the next request no\nlonger sees the site. Within the organisation, admins and unrestricted members see all of\nthat; a *restricted* member sees only the sites their teams grant (whole groups and single\nsites). A site the key's owner may not see, for whatever reason, answers `404 not_found` on\nevery endpoint, exactly like a site that does not exist, so nobody learns which other sites\nor organisations exist. `GET /api/v1/sites` lists only the visible sites.\n\n## Conventions\n\n- JSON everywhere, `snake_case` keys, timestamps as RFC 3339 strings in UTC.\n- Days are calendar days in the **site's time zone**.\n- Errors are an HTTP status plus `{\"error\": \"<code>\", \"message\": \"<human text>\"}`.\n- Privacy: Pegel never stores IP addresses, user agents, cookies or full query strings.\n  Visitors are counted with a daily-salted 8-byte id, so `visitors` are distinct per day.\n\n## MCP (Model Context Protocol)\n\n`POST /mcp` is a stateless MCP server (Streamable HTTP, JSON responses, no SSE) with the\ntools `list_sites`, `get_stats`, `get_timeseries`, `get_breakdown` and `get_realtime`, so\nClaude, ChatGPT, Cursor and other MCP clients can answer questions about your analytics:\n\n```bash\nclaude mcp add --transport http pegel https://pegel-api.rigilab.com/mcp \\\n  --header \"Authorization: Bearer pgl_…\"\n```\n\nThe tools take the same `period`, `from`, `to` and filters as the REST endpoints and return\nthe same JSON objects. See the `POST /mcp` operation below.\n","license":{"name":"Proprietary","url":"https://pegel.rigilab.com"},"summary":"Cookieless web analytics, read API for scripts, BI tools and AI assistants.","title":"Pegel API","version":"1"},"openapi":"3.1.0","paths":{"/api/v1/config":{"get":{"description":"Public, no authentication. The hub's version, its public URL and the tracker script URL.","operationId":"getConfig","responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Config"}}},"description":"Hub configuration."}},"security":[],"summary":"Hub version and URLs","tags":["Public"]}},"/api/v1/sites":{"get":{"description":"Every site the caller sees, sorted by name. Restricted users (groups and teams) get only\nthe sites their teams grant. `visitors_24h` counts the rolling last 24 hours.\n","operationId":"listSites","responses":{"200":{"content":{"application/json":{"schema":{"items":{"$ref":"#/components/schemas/Site"},"type":"array"}}},"description":"The visible sites."},"401":{"$ref":"#/components/responses/Unauthorized"}},"summary":"List sites","tags":["Sites"]}},"/api/v1/sites/{id}":{"get":{"operationId":"getSite","parameters":[{"$ref":"#/components/parameters/SiteId"}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Site"}}},"description":"The site."},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}},"summary":"Get a site","tags":["Sites"]}},"/api/v1/sites/{id}/stats/aggregate":{"get":{"description":"Visitors, visits, page views, views per visit, bounce rate and visit duration for the\nperiod, plus the same numbers for the period right before (`previous`).\n","operationId":"getAggregate","parameters":[{"$ref":"#/components/parameters/SiteId"},{"$ref":"#/components/parameters/Period"},{"$ref":"#/components/parameters/From"},{"$ref":"#/components/parameters/To"},{"$ref":"#/components/parameters/FilterPage"},{"$ref":"#/components/parameters/FilterEntryPage"},{"$ref":"#/components/parameters/FilterSource"},{"$ref":"#/components/parameters/FilterUtmSource"},{"$ref":"#/components/parameters/FilterUtmMedium"},{"$ref":"#/components/parameters/FilterUtmCampaign"},{"$ref":"#/components/parameters/FilterCountry"},{"$ref":"#/components/parameters/FilterBrowser"},{"$ref":"#/components/parameters/FilterOs"},{"$ref":"#/components/parameters/FilterDevice"},{"$ref":"#/components/parameters/FilterEvent"}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Aggregate"}}},"description":"Totals for the period and the one before."},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}},"summary":"Totals","tags":["Stats"]}},"/api/v1/sites/{id}/stats/breakdown":{"get":{"description":"The top values of one property (pages, sources, countries, …), sorted by visitors.\n\n- `count` is page views for `page`; visits for `entry_page`, `exit_page`, `source`,\n  `referrer`, `utm_*`, `country`, `browser`, `os`, `device`; occurrences for `event`\n  (custom events only).\n- `percentage` = this row's `visitors` / all visitors in the (filtered) period × 100.\n- Empty values are reported as `Direct / None` for `source` and `referrer` and as\n  `(none)` otherwise.\n","operationId":"getBreakdown","parameters":[{"$ref":"#/components/parameters/SiteId"},{"description":"What to break down by.","example":"source","in":"query","name":"property","required":true,"schema":{"$ref":"#/components/schemas/BreakdownProperty"}},{"description":"Number of rows.","in":"query","name":"limit","schema":{"default":10,"maximum":100,"minimum":1,"type":"integer"}},{"$ref":"#/components/parameters/Period"},{"$ref":"#/components/parameters/From"},{"$ref":"#/components/parameters/To"},{"$ref":"#/components/parameters/FilterPage"},{"$ref":"#/components/parameters/FilterEntryPage"},{"$ref":"#/components/parameters/FilterSource"},{"$ref":"#/components/parameters/FilterUtmSource"},{"$ref":"#/components/parameters/FilterUtmMedium"},{"$ref":"#/components/parameters/FilterUtmCampaign"},{"$ref":"#/components/parameters/FilterCountry"},{"$ref":"#/components/parameters/FilterBrowser"},{"$ref":"#/components/parameters/FilterOs"},{"$ref":"#/components/parameters/FilterDevice"},{"$ref":"#/components/parameters/FilterEvent"}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Breakdown"}}},"description":"The top values."},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}},"summary":"Top list","tags":["Stats"]}},"/api/v1/sites/{id}/stats/realtime":{"get":{"description":"Distinct visitors with an event in the last 5 minutes and their current pages (top 10).","operationId":"getRealtime","parameters":[{"$ref":"#/components/parameters/SiteId"}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Realtime"}}},"description":"Current visitors."},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}},"summary":"Visitors right now","tags":["Stats"]}},"/api/v1/sites/{id}/stats/timeseries":{"get":{"description":"Visitors and page views per bucket. Every bucket in the range is present, zeros\nincluded. `interval` is `hour` for `today`, `yesterday` and one-day custom ranges\n(`date` = `2026-11-22T14:00`, local time of the site), `month` for `12m`\n(`date` = `2026-11`) and `day` otherwise (`date` = `2026-11-21`).\n","operationId":"getTimeseries","parameters":[{"$ref":"#/components/parameters/SiteId"},{"$ref":"#/components/parameters/Period"},{"$ref":"#/components/parameters/From"},{"$ref":"#/components/parameters/To"},{"$ref":"#/components/parameters/FilterPage"},{"$ref":"#/components/parameters/FilterEntryPage"},{"$ref":"#/components/parameters/FilterSource"},{"$ref":"#/components/parameters/FilterUtmSource"},{"$ref":"#/components/parameters/FilterUtmMedium"},{"$ref":"#/components/parameters/FilterUtmCampaign"},{"$ref":"#/components/parameters/FilterCountry"},{"$ref":"#/components/parameters/FilterBrowser"},{"$ref":"#/components/parameters/FilterOs"},{"$ref":"#/components/parameters/FilterDevice"},{"$ref":"#/components/parameters/FilterEvent"}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Timeseries"}}},"description":"One point per bucket."},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}},"summary":"Chart data","tags":["Stats"]}},"/mcp":{"post":{"description":"A stateless [Model Context Protocol](https://modelcontextprotocol.io) server\n(Streamable HTTP transport, JSON responses, no SSE). Point an MCP client at this URL with\nthe API key as bearer token; a login JWT works too. `GET /mcp` answers `405`.\n\nJSON-RPC methods: `initialize`, `notifications/initialized` (answers `202` without a\nbody), `ping`, `tools/list`, `tools/call`.\n\nTools (all read-only; `site` is a domain such as `example.com` or a numeric site id;\n`period`, `from`, `to` work as in the stats endpoints and `filters` is an object such as\n`{\"source\": \"Google\", \"country\": \"CH\"}` with the `f.*` names without the prefix):\n\n| tool | arguments | returns |\n|------|-----------|---------|\n| `list_sites` | none | the sites the key's owner sees, with `visitors_24h` |\n| `get_stats` | `site`, `period?`, `from?`, `to?`, `filters?` | the aggregate object incl. `previous` |\n| `get_timeseries` | `site`, `period?`, `from?`, `to?`, `filters?` | the timeseries object |\n| `get_breakdown` | `site`, `property`, `period?`, `from?`, `to?`, `filters?`, `limit?` | the breakdown object |\n| `get_realtime` | `site` | the realtime object |\n\nResults come as one `text` content item holding the JSON, plus the same object as\n`structuredContent`. Tool errors (unknown site, bad period) are results with\n`isError: true`; a site the key's owner may not see is an unknown site.\n","operationId":"mcp","requestBody":{"content":{"application/json":{"examples":{"get_stats":{"summary":"Visitors of the last 7 days from Switzerland","value":{"id":2,"jsonrpc":"2.0","method":"tools/call","params":{"arguments":{"filters":{"country":"CH"},"period":"7d","site":"example.com"},"name":"get_stats"}}},"tools_list":{"summary":"List the tools","value":{"id":1,"jsonrpc":"2.0","method":"tools/list"}}},"schema":{"$ref":"#/components/schemas/JsonRpcRequest"}}},"required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/JsonRpcResponse"}}},"description":"The JSON-RPC response."},"202":{"description":"A notification was accepted (no body)."},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}},"summary":"MCP server (JSON-RPC 2.0)","tags":["MCP"]}}},"security":[{"apiKey":[]}],"servers":[{"description":"Pegel","url":"https://pegel-api.rigilab.com"}],"tags":[{"description":"The sites the key's owner sees.","name":"Sites"},{"description":"Visitors, visits, page views, bounce rate, visit duration, charts and top lists of a site.\nAll stats endpoints take `period` (`from`/`to` for `custom`) and the `f.*` filters.\n","name":"Stats"},{"description":"Model Context Protocol endpoint for AI assistants.","name":"MCP"},{"description":"No authentication.","name":"Public"}]}