Skip to main content

Analytics API

The Analytics module provides real-time business intelligence — revenue dashboards, conversion funnels, inventory KPIs, HR metrics, support performance, and AI-powered forecasting. Data is aggregated server-side and returned in chart-ready formats.


Endpoints

MethodPathDescription
GET/api/analytics/revenueRevenue metrics (time-series)
GET/api/analytics/salesSales funnel and pipeline
GET/api/analytics/productsProduct performance
GET/api/analytics/customersCustomer acquisition and LTV
GET/api/analytics/inventoryInventory health metrics
GET/api/analytics/hrHR headcount and attendance
GET/api/analytics/supportHelpdesk KPIs
GET/api/analytics/marketingCampaign and email metrics
GET/api/analytics/forecastAI revenue forecast
GET/api/analytics/anomaliesDetected metric anomalies
GET/api/analytics/dashboardsList saved dashboards
POST/api/analytics/reports/exportExport report to Excel/CSV

Common Query Parameters

All analytics endpoints accept these parameters:

ParameterTypeDescription
fromISO 8601Period start date
toISO 8601Period end date
groupByday | week | month | quarterTime aggregation
currencystringCurrency for monetary values (default: usd)

Revenue Metrics

GET /api/analytics/revenue?from=2026-01-01&to=2026-03-31&groupBy=month

Response

{
"summary": {
"totalRevenue": 3780000,
"revenueGrowth": 0.23,
"mrr": 1280000,
"arr": 15360000,
"avgOrderValue": 54000,
"currency": "usd"
},
"timeSeries": [
{ "period": "2026-01", "revenue": 980000, "orders": 18, "refunds": 15000 },
{ "period": "2026-02", "revenue": 1240000, "orders": 23, "refunds": 0 },
{ "period": "2026-03", "revenue": 1560000, "orders": 29, "refunds": 49900 }
],
"byProduct": [
{ "productName": "Shopify Connector", "revenue": 1498000, "units": 30 },
{ "productName": "Amazon Connector", "revenue": 998000, "units": 20 }
]
}

Sales Funnel

GET /api/analytics/sales?from=2026-01-01&to=2026-03-31

Response

{
"funnel": [
{ "stage": "leads", "count": 420, "value": 20580000 },
{ "stage": "qualified", "count": 210, "value": 10290000 },
{ "stage": "proposal", "count": 95, "value": 4655000 },
{ "stage": "negotiation", "count": 48, "value": 2352000 },
{ "stage": "won", "count": 70, "value": 3430000 }
],
"winRate": 0.167,
"avgDealSize": 49000,
"avgCycledays": 18
}

Customer Metrics

GET /api/analytics/customers?from=2026-01-01&to=2026-03-31

Response

{
"newCustomers": 48,
"churnedCustomers": 3,
"netGrowth": 45,
"avgLtv": 298000,
"cac": 12000,
"ltvCacRatio": 24.8,
"retentionRate": 0.94,
"byAcquisitionChannel": [
{ "channel": "organic_search", "customers": 22, "percent": 0.46 },
{ "channel": "direct", "customers": 14, "percent": 0.29 },
{ "channel": "referral", "customers": 12, "percent": 0.25 }
]
}

AI Revenue Forecast

Uses historical data and seasonality patterns to project future revenue.

GET /api/analytics/forecast?periods=3&granularity=month

Response

{
"model": "linear_regression_with_seasonality",
"generatedAt": "2026-03-20T12:00:00Z",
"forecast": [
{
"period": "2026-04",
"predicted": 1820000,
"confidenceLow": 1650000,
"confidenceHigh": 1990000
},
{
"period": "2026-05",
"predicted": 2050000,
"confidenceLow": 1840000,
"confidenceHigh": 2260000
},
{
"period": "2026-06",
"predicted": 2340000,
"confidenceLow": 2090000,
"confidenceHigh": 2590000
}
],
"confidence": 0.87,
"currency": "usd"
}

Anomaly Detection

Returns metrics that have deviated significantly from their historical baseline.

GET /api/analytics/anomalies?severity=high

Query Parameters

ParameterTypeDescription
severitylow | medium | highMinimum severity level
metricstringFilter by metric name

Response

{
"anomalies": [
{
"metric": "daily_revenue",
"severity": "high",
"detectedAt": "2026-03-19T23:00:00Z",
"expected": 52000,
"actual": 12000,
"deviation": -0.77,
"description": "Revenue 77% below 30-day moving average on 2026-03-19"
}
]
}

Export Report

POST /api/analytics/reports/export
Content-Type: application/json

{
"reportType": "revenue",
"from": "2026-01-01",
"to": "2026-03-31",
"format": "xlsx",
"groupBy": "month"
}

Returns a binary file stream (Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet for Excel, text/csv for CSV).

curl -o report_q1_2026.xlsx \
-X POST \
-H "Authorization: Bearer eco_live_..." \
-H "Content-Type: application/json" \
-d '{"reportType":"revenue","from":"2026-01-01","to":"2026-03-31","format":"xlsx","groupBy":"month"}' \
https://api.ecosire.com/api/analytics/reports/export

Export formats: xlsx, csv


Status Codes

CodeScenario
200Metrics returned or export file served
400Invalid date range or unknown groupBy
404Dashboard or report not found
422from date is after to date