Skip to main content

API Reference

Analytics API

Analytics API

The Analytics API provides menu performance data for restaurant owners and a tracking endpoint for recording customer interactions.

GET /api/analytics

Retrieve analytics data for your restaurant.

Auth: Required (Bearer token). Also verifies restaurant ownership.

Response (200 OK)

{
  "success": true,
  "data": {
    "totalViews": 1250,
    "uniqueVisitors": 890,
    "averageDuration": 45.2,
    "topItems": [
      {
        "id": "uuid",
        "name": "Margherita Pizza",
        "views": 340
      }
    ],
    "modelCoverage": 0.85
  }
}

Note: The modelCoverage field indicates the percentage of menu items that have a READY 3D model (3D Menu Pro only). It uses a LEFT JOIN to the three_d_models table where status = 'READY'.

POST /api/analytics/track

Record a new page view. Used by the menu viewer client.

Auth: Public (no token required)

Request Body

{
  "restaurantId": "uuid",
  "menuItemId": "uuid"
}

Response (201 Created)

{
  "success": true,
  "data": {
    "id": "uuid"
  }
}

Important: The response wraps data in data.data — use response.data?.id from the parsed JSON, not response.id.

PATCH /api/analytics/track

Update an existing view record with duration and interaction data.

Auth: Public (no token required)

Request Body

{
  "viewId": "uuid",
  "duration": 45,
  "interactions": 3
}

Response (200 OK)

{
  "success": true,
  "data": {
    "id": "uuid",
    "duration": 45,
    "interactions": 3
  }
}

Note: Always use fetch with keepalive: true for analytics tracking calls. Do not use navigator.sendBeacon, which only supports POST with text/plain content type.