This document provides a comprehensive guide to the Lena API, including available endpoints, request/response formats, and usage examples.
https://api.lena.com/v1
All API requests require authentication using a Bearer token included in the Authorization header.
Authorization: Bearer YOUR_API_KEY- Rate Limit: 100 requests per minute per IP address
- Headers:
X-RateLimit-Limit: Total requests allowed in the current periodX-RateLimit-Remaining: Remaining requests in the current periodX-RateLimit-Reset: Timestamp when the rate limit resets
Standard HTTP status codes are used to indicate success or failure:
200 OK: Request was successful201 Created: Resource was created successfully400 Bad Request: Invalid request parameters401 Unauthorized: Missing or invalid authentication403 Forbidden: Insufficient permissions404 Not Found: Resource not found429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Server error
Error responses include a JSON object with error details:
{
"error": {
"code": "error_code",
"message": "Human-readable error message",
"details": {
"field": "Additional error details"
}
}
}Log a new analytics event.
POST /api/analytics/eventsRequest Body:
{
"event": "page_view",
"properties": {
"url": "https://example.com",
"referrer": "https://google.com",
"screen_width": 1920,
"screen_height": 1080
},
"user_id": "user_123",
"session_id": "session_456"
}Response:
{
"success": true,
"event_id": "evt_789"
}Retrieve aggregated analytics data.
GET /api/analytics/aggregate?metric=page_views&start_date=2023-01-01&end_date=2023-01-31&interval=dayQuery Parameters:
metric(required): The metric to aggregate (page_views, users, sessions, etc.)start_date(required): Start date in YYYY-MM-DD formatend_date(required): End date in YYYY-MM-DD formatinterval: Time interval (minute, hour, day, week, month)filters: JSON string of filters to apply
Response:
{
"data": [
{
"date": "2023-01-01T00:00:00Z",
"value": 1234
},
{
"date": "2023-01-02T00:00:00Z",
"value": 1456
}
],
"summary": {
"total": 123456,
"average": 1234.56,
"change": 12.3
}
}Retrieve cohort analysis data.
GET /api/analytics/cohorts?cohort_type=week&metric=retention&periods=12Query Parameters:
cohort_type: Time period for cohorts (day, week, month)metric: Metric to analyze (retention, revenue, etc.)periods: Number of periods to include
Response:
{
"cohorts": [
{
"cohort": "2023-01",
"size": 1000,
"data": [
{
"period": 0,
"value": 1.0
},
{
"period": 1,
"value": 0.65
}
]
}
]
}Analyze user conversion through a series of steps.
POST /api/analytics/funnelRequest Body:
{
"steps": [
{"event": "page_view", "properties": {"url": "/signup"}},
{"event": "signup_started"},
{"event": "signup_completed"}
],
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}Response:
{
"steps": [
{
"name": "page_view",
"count": 1000,
"conversion_rate": 1.0
},
{
"name": "signup_started",
"count": 500,
"conversion_rate": 0.5
},
{
"name": "signup_completed",
"count": 250,
"conversion_rate": 0.25
}
],
"total_conversion_rate": 0.25
}Analyze user retention over time.
GET /api/analytics/retention?cohort_type=week&periods=8Response:
{
"cohorts": [
{
"cohort": "2023-01-01",
"sizes": [1000, 350, 200, 150, 120, 100, 90, 80],
"retention_rates": [1.0, 0.35, 0.2, 0.15, 0.12, 0.1, 0.09, 0.08]
}
]
}Export analytics data in various formats.
GET /api/analytics/export?format=csv&start_date=2023-01-01&end_date=2023-01-31Query Parameters:
format: Export format (csv, json, xlsx)start_date: Start date in YYYY-MM-DD formatend_date: End date in YYYY-MM-DD format
Response:
- Returns a file in the requested format
curl -X POST https://api.lena.com/v1/api/analytics/events \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"event":"page_view","properties":{"url":"https://example.com"}}'const trackEvent = async (event, properties) => {
const response = await fetch('https://api.lena.com/v1/api/analytics/events', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
event,
properties,
user_id: 'user_123',
session_id: 'session_456'
})
});
return await response.json();
};The API can send webhook notifications for various events. Configure webhook URLs in your dashboard.
event.tracked: When a new event is trackeduser.created: When a new user is identifiedalert.triggered: When an alert condition is met
{
"event": "event.tracked",
"data": {
"event_id": "evt_789",
"event": "page_view",
"timestamp": "2023-01-01T12:00:00Z",
"properties": {
"url": "https://example.com"
},
"user_id": "user_123"
}
}- Always include a
user_idorsession_idwith events for accurate tracking - Use consistent event names and property names
- Batch events when possible to reduce API calls
- Implement retry logic for failed requests
- Respect rate limits and implement exponential backoff
For additional help, contact support@lena.com or visit our developer portal.