Skip to main content

Analytics Integration

How v0- and Claude-built pages access the Cockpit analytics system — via MCP tools and a reusable tracking snippet.

Overview

Cockpit uses Umami as the analytics platform. Each center can configure its own Umami website ID and URL (Dashboard → Center → Analytics). External pages (v0 builds, Claude pages) can:

  1. Embed Umami trackingV0AnalyticsSnippet
  2. Read website analyticscockpit_analytics_website_stats, cockpit_analytics_umami_events, cockpit_analytics_umami_export, cockpit_analytics_website_insights
  3. Read content performancecockpit_analytics_content_metrics, cockpit_analytics_content_performance, cockpit_analytics_content_performance_batch, cockpit_analytics_content_performance_insights
  4. Signage & reportingcockpit_analytics_signage, cockpit_analytics_reporting, cockpit_analytics_trending, cockpit_analytics_companion_stats
  5. Capture custom eventscockpit_analytics_track_event (Cockpit DB, not Umami)

MCP Tools (Umami & Analytics)

All analytics tools run on mcp-cockpit-os and require COCKPIT_AGENCYOS_API_KEY (Bearer). The dashboard also accepts session cookies on the same API routes.

MCP toolSourceContent
cockpit_analytics_website_statsUmamiFull: stats, series, top pages, referrers, devices, browsers, OS, countries, optional events
cockpit_analytics_umami_eventsUmamiCustom events (raw list)
cockpit_analytics_umami_exportUmamiMulti-period 30 / 90 / 365 days
cockpit_analytics_website_insightsUmami + AIWebsite insights (traffic, bounce, bot, …)
cockpit_analytics_content_metricsUmami + DBAggregated content views
cockpit_analytics_content_performanceUmami + DBSingle item (news/offer/event/shop/job/hotpick)
cockpit_analytics_content_performance_batchUmami + DBUp to 40 items
cockpit_analytics_content_performance_insightsUmami + AIAI tips per item
cockpit_analytics_signageSignage API / Companion UmamiStele/kiosk analytics
cockpit_analytics_companion_statsUmami (system-wide)NOW!/Companion website
cockpit_analytics_reportingCockpit DBAI usage, searches, funnel
cockpit_analytics_trendingChatbot DBTrending shops/offers (no Umami)
cockpit_analytics_track_eventCockpit DBWrite custom events (not Umami)

Periods (period): 24h, 7d, 30d, 90d, 365d.

Discover: cockpit_mcp_discover_tools(query: "analytics").

cockpit_analytics_website_stats

Full Umami website analytics for a center.

Parameters

ParameterTypeDefaultDescription
centerIdUUIDCenter
period24h | 7d | 30d | 90d | 365d30dPeriod
includeEventsbooleanfalseInclude Umami custom events
metricsLimit1–5015Max entries per top list

Prerequisite: Analytics enabled, umamiWebsiteId, server UMAMI_PASSWORD.

Global content performance (Umami + AI)

Server modules under apps/dashboard/src/lib/analytics/ (barrel: @/lib/analytics):

ModulePurpose
center-umami-config.tsCenter analytics flags + umamiWebsiteId
content-url-paths.tsPublic detail paths (news, offers, events, shops, jobs)
content-umami-metrics.tsSingle fetch + UmamiUrlMetricsCache (one Umami call per center)
content-performance-service.tsSnapshot: views, engagement, quality
content-performance-ai.tsAI recommendations per item (OPENAI_API_KEY)

HTTP (session or agency API key + center access)

RouteDescription
GET /api/analytics/website-stats?centerId=&timeframe=Full Umami website analytics
GET /api/analytics/umami-events?centerId=Umami custom events
GET /api/analytics/umami-export?centerId=Multi-period export
GET /api/analytics/insights?centerId=AI website insights
GET /api/analytics/signage?centerId=Signage/stele
GET /api/analytics/companion-statsCompanion Umami (system-wide, API key only)
GET /api/analytics/reporting?centerId=Center reporting
GET /api/analytics/trending?centerId=Chatbot trending
GET /api/analytics/content-performance?centerId=&kind=&id=Performance snapshot for one item
POST /api/analytics/content-performance/batchBody: { centerId, items: [{ kind, id }] } — batch with shared Umami cache
POST /api/analytics/content-performance/insightsBody: { centerId, kind, id, context? } — AI insights + snapshot
GET /api/content/recent?centerId=Content overview: views for all content types
GET /api/content/metrics?centerId=Aggregated views (Umami detail paths, 90 days)

Requirements: UMAMI_PASSWORD on the server; center with analyticsEnabled, provider umami or both, umamiWebsiteId. Optional umamiUrl per center.

Client: Hook useContentPerformance(); UI at /dashboard/contentContent-Insights button.

kind: news | offer | event | shop | job | hotpick


Dashboard: AI insights (internal)

GET /api/analytics/insights?centerId={uuid}&timeframe=day|week|month

  • Session or agency API key with center access
  • Reads Umami stats + events; generates 3–5 insights via gpt-4o-mini (OPENAI_API_KEY)
  • UI: /dashboard/analytics → teaser in Website tab + AI Insights tab

cockpit_analytics_content_metrics

Aggregated metrics for the content overview (GET /api/content/metrics): views (Umami detail paths + DB), engagement, categoryBreakdown.

Parameters

ParameterTypeRequiredDescription
centerIdstring (UUID)Center UUID

Example

cockpit_analytics_content_metrics(centerId: "f1a2b3c4-...")

cockpit_analytics_content_performance

Snapshot for one item (Umami, DB, quality, engagement).

ParameterTypeRequiredDescription
centerIdstring (UUID)Center
kindnews | offer | event | shop | job | hotpickType
idstring (UUID)Item ID

cockpit_analytics_content_performance_batch

Multiple snapshots in one request (max. 40 items) — one Umami call per center. Prefer over many single GETs after cockpit_center_context.

ParameterTypeRequiredDescription
centerIdstring (UUID)Center
items{ kind, id }[]1–40 entries

Example

cockpit_analytics_content_performance_batch(
centerId: "f1a2b3c4-...",
items: [
{ kind: "news", id: "…" },
{ kind: "offer", id: "…" }
]
)

Response (excerpt): data[] with { kind, id, data?: snapshot } or { error: "not_found"|"failed" }; meta.umamiBatch: true when Umami is active.

cockpit_analytics_content_performance_insights

AI recommendations for one item (POST, optional context).

ParameterTypeRequiredDescription
centerIdstring (UUID)Center
kind / idas aboveItem
contextstringExtra context for AI

cockpit_analytics_track_event

Records a custom usage event in the Cockpit DB (monthly reporting).

Parameters

ParameterTypeRequiredDefaultDescription
centerIdstring (UUID)Center UUID
eventTypestringe.g. "offer_click"
source"website" | "kiosk" | "companion" | "app""website"Event source
metadataobjectOptional payload

Tracking snippet for external pages

V0AnalyticsSnippet

React component (apps/center-website/components/analytics/v0-analytics-snippet.tsx) embeds Umami in v0/Claude pages.

Prerequisites

  • Next.js with next/script
  • Center has analytics enabled and umamiWebsiteId set

Props

PropTypeRequiredDescription
centerIdstringCenter UUID
umamiWebsiteIdstringOptional; loaded via API if omitted
umamiUrlstringDefault: https://analytics.cockpit-os.de

Usage

import { V0AnalyticsSnippet } from '@/components/analytics/v0-analytics-snippet'

export default function Layout({ children }) {
return (
<>
<V0AnalyticsSnippet centerId="f1a2b3c4-uuid-of-center" />
{children}
</>
)
}

Behavior

  • Waits for cookie consent (vanilla-cookieconsent)
  • Dev: script may load without consent for testing
  • Renders nothing if no website ID or analytics disabled (no error)

API endpoints

EndpointMethodAuthDescription
/api/analytics/website-statsGETBearerUmami traffic stats
/api/analytics/footfallGETSessionFootfall (mock until live source)
/api/analytics/usage-eventsPOSTBearerCustom events
/api/analytics/content-performanceGETBearerSnapshot per item
/api/analytics/content-performance/batchPOSTBearerMultiple snapshots
/api/analytics/content-performance/insightsPOSTBearerAI + snapshot
/api/analytics/insightsGETSessionWebsite AI insights
/api/content/metricsGETBearerAggregated content metrics
/api/content/recentGETBearerRecent content + Umami views
/api/content/news/{id}/performanceGET/POSTSessionNews SEO (POST = OpenAI)

Public (v0, no session): GET /api/agencyos/v1/public/visitor-surface?centerId=data.tracking for V0AnalyticsSnippet.

MCP uses COCKPIT_AGENCYOS_API_KEY as Bearer on dashboard routes.

Content overview (/dashboard/content)

  • GET /api/content/metrics: Views from Umami detail paths (90 days) + DB for hot picks/jobs engagement.
  • GET /api/content/recent: One Umami top-URL call per center; path matching via content-url-paths.ts and content-umami-match-opts.ts (center slug prefix, shop chain slug, trailing slash).
  • Detail pages: ContentPerformanceCard + APIs above (news, offers, events, jobs, shops, shop locations).

Content detail: Umami shows traffic, Cockpit shows 0

Applies to all content types above. Common causes: public URL slug differs from Cockpit (e.g. shop chain slug /shops/al-carbon/ vs UUID), wrong Umami website ID, or missing UMAMI_PASSWORD. Matching uses path variants including /[centerSlug]/… and shop chain segments. Reload the Analytics tab after deploy; a match shows Umami URL.


Verification (checklist)

1. Cockpit configuration

CheckHow
Analytics onDashboard → Center → Analytics → enabled, provider umami or both
umamiWebsiteId setSame tab or center API
ServerUMAMI_PASSWORD on Render/dashboard
AI insightsOPENAI_API_KEY (optional)

MCP: cockpit_public_visitor_surface or cockpit_get_center_website_configdata.tracking.

2. Center website (standard layout)

CheckExpected
Script loadsDevTools → Network: script.js with data-website-id
Cookie consentAccept analytics — otherwise no script
PageviewsUmami UI or cockpit_analytics_website_stats
Detail URLse.g. /aktuelles/news/{slug}, /angebote/{slug} — see content-url-paths.ts

Different paths (e.g. /nachrichten/… only): extend content-url-paths.ts in the dashboard — no template change if routes already exist.

3. External / v0 page (no app/[slug]/layout)

<V0AnalyticsSnippet centerId="<center-uuid>" />

Verify: cockpit_public_visitor_surfacedata.tracking.umamiWebsiteId not empty.

4. Content performance in dashboard

CheckAPI / UI
Overview loads quickly/dashboard/content — ~12s Umami timeout max, then DB fallback
Views in tableViews column, optionally "(Umami)"
Detail pagePerformance card on news/offer/event/shop/job
MCP aggregatecockpit_analytics_content_metrics
MCP itemscockpit_analytics_content_performance or cockpit_analytics_content_performance_batch
MCP AIcockpit_analytics_content_performance_insights

5. Custom events (optional)

Website: trackEvent('offer_click', { offerId }) from umami-analytics.tsx.
MCP: cockpit_analytics_track_event → DB, not Umami pageviews.

6. Quick curl test

curl -s -H "Authorization: Bearer $COCKPIT_AGENCYOS_API_KEY" \
"https://dashboard.cockpit-os.de/api/content/metrics?centerId=<UUID>"

curl -s -X POST -H "Authorization: Bearer $COCKPIT_AGENCYOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"centerId":"<UUID>","items":[{"kind":"news","id":"<NEWS_UUID>"}]}' \
"https://dashboard.cockpit-os.de/api/analytics/content-performance/batch"

Footfall

Dashboard: /dashboard/analytics/footfall

API: GET /api/analytics/footfall?centerId=<uuid>

See Footfall API preparation.


Architecture

External page (v0/Claude)

├─► V0AnalyticsSnippet ──► Umami script
│ └─ public visitor-surface API

└─► cockpit_analytics_* (MCP)
├─► /api/analytics/website-stats ──► Umami API
├─► /api/content/metrics ──► Umami + Prisma
├─► /api/analytics/content-performance ──► Umami + Prisma
└─► /api/analytics/usage-events ──► Prisma

Data flow

  1. Page view: V0AnalyticsSnippet → Umami tracks directly
  2. Custom events: cockpit_analytics_track_event → Cockpit DB
  3. Read stats: MCP tools → dashboard APIs → Umami / Prisma

Nutzungsstatistik: Seitenaufrufe werden anonymisiert erfasst. Im Umami-Dashboard nach diesem Pfad filtern: /en/developer-guide/analytics-integration