Analytics API
File: app/api/analytics/route.ts
POST /api/analytics
Records an analytics event to Supabase.
Request body
{
"gpx": "https://www.bttpirineus.org/wp-content/uploads/ruta.gpx",
"event": "view",
"event_name": "view",
"event_group": "engagement",
"share_channel": null,
"ui_surface": "embed_bottom_bar",
"session_id": "abc123",
"referrer_host": "www.bttpirineus.org",
"meta_json": {}
}| Field | Required | Description |
|---|---|---|
gpx | Yes | GPX file URL |
event_name | Yes | Must match /^[a-z0-9_:-]{1,64}$/i |
event | No | Legacy field: view, download, or share |
event_group | No | Auto-inferred if not provided |
share_channel | No | Share platform identifier |
ui_surface | No | Where the action occurred |
session_id | No | Client-generated session ID |
referrer_host | No | Extracted from document.referrer |
meta_json | No | Arbitrary metadata object |
Response
{ "ok": true }If Supabase is not configured, silently returns { "ok": true } without writing.
GET /api/analytics
Returns aggregated event counts for a single GPX URL.
Parameters
| Parameter | Required | Description |
|---|---|---|
gpx | Yes | GPX file URL to query |
Response
{
"views": 42,
"downloads": 12,
"shares": 3
}Cache: s-maxage=60 (60-second server-side cache).
If Supabase is not configured, returns zeros.