Skip to main content

Overview

The Analytics API provides endpoints to track user events on tenant landing pages and retrieve analytics data for dashboards. Events are tracked anonymously using hashed IP addresses for privacy.

Track Event

Track analytics events from the frontend. This is a public endpoint that does not require authentication.

Rate Limiting

  • Limit: 100 events per minute per tenant
  • Status Code: 429 when limit is exceeded

Request Body

tenant_id
integer
required
The ID of the tenant
event_type
string
required
Type of event. Must be one of:
  • pageview - Page view
  • click_whatsapp - WhatsApp button click
  • click_call - Call button click
  • click_toggle_currency - Currency toggle click
  • time_on_page - Time spent on page
  • qr_scan - QR code scan
  • product_click - Product click
metadata
object
Optional additional event metadata

Response

{
  "success": true
}

Privacy

  • IP addresses are hashed with SHA-256 before storage
  • Only the first 45 characters of the hash are stored
  • User agents and referrers are stored for analytics purposes

Example

fetch('/api/analytics/track', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    tenant_id: 1,
    event_type: 'click_whatsapp',
    metadata: {
      button_location: 'hero'
    }
  })
});

Get Analytics Data

Retrieve analytics data for a tenant’s dashboard. This endpoint requires authentication.

Path Parameters

tenantId
integer
required
The ID of the tenant

Response

success
boolean
Whether the request was successful
data
object
{
  "success": true,
  "data": {
    "visitors_today": 15,
    "visitors_week": 87,
    "whatsapp_clicks": 12,
    "call_clicks": 5,
    "currency_toggles": 23,
    "qr_scans": 8,
    "avg_time_on_page": 120,
    "last_7_days": [
      {
        "date": "2026-03-02",
        "visitors": 10
      },
      {
        "date": "2026-03-03",
        "visitors": 12
      },
      {
        "date": "2026-03-04",
        "visitors": 15
      },
      {
        "date": "2026-03-05",
        "visitors": 18
      },
      {
        "date": "2026-03-06",
        "visitors": 14
      },
      {
        "date": "2026-03-07",
        "visitors": 13
      },
      {
        "date": "2026-03-08",
        "visitors": 15
      }
    ]
  }
}

Get Today’s Analytics

Retrieve a quick summary of today’s analytics. This endpoint requires authentication.

Path Parameters

tenantId
integer
required
The ID of the tenant

Response

success
boolean
Whether the request was successful
visitors_today
integer
Unique visitors today
whatsapp_clicks
integer
WhatsApp button clicks today
qr_scans
integer
QR code scans today
products_viewed
integer
Product clicks today
{
  "success": true,
  "visitors_today": 15,
  "whatsapp_clicks": 3,
  "qr_scans": 2,
  "products_viewed": 8
}

Build docs developers (and LLMs) love