Opensource Site Tracking Wiki
Self-hosted private analytics for real-time multi-site tracking.
Brought to you by:
autobotsolution
OpenSite Analytics provides a RESTful API for managing sites, tracking analytics, and user authentication.
http://localhost:8000
All API endpoints (except login and register) require JWT authentication.
Authorization: Bearer <your_jwt_token>
Content-Type: application/json
POST /api/auth/login
Request Body:
{
"email": "admin@example.com",
"password": "admin123"
}
Response:
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "bearer",
"user": {
"email": "admin@example.com",
"id": 1
}
}
POST /api/auth/register
Request Body:
{
"email": "user@example.com",
"password": "securepassword"
}
Response:
{
"email": "user@example.com",
"id": 2,
"created_at": "2026-04-29T12:00:00"
}
GET /api/auth/me
Response:
{
"email": "admin@example.com",
"id": 1,
"created_at": "2026-04-29T12:00:00"
}
GET /api/sites
Response:
[
{
"id": 1,
"name": "My Website",
"domain": "example.com",
"site_key": "abc123",
"api_key": "xyz789",
"created_at": "2026-04-29T12:00:00",
"is_active": true
}
]
GET /api/sites/{site_id}
Response:
{
"id": 1,
"name": "My Website",
"domain": "example.com",
"site_key": "abc123",
"api_key": "xyz789",
"created_at": "2026-04-29T12:00:00",
"is_active": true
}
POST /api/sites
Request Body:
{
"name": "My Website",
"domain": "example.com"
}
Response:
{
"id": 1,
"name": "My Website",
"domain": "example.com",
"site_key": "abc123",
"api_key": "xyz789",
"created_at": "2026-04-29T12:00:00",
"is_active": true
}
GET /api/analytics/{site_id}?period=7days
Query Parameters:
period: Time period for analytics (default: 7days)1day, 7days, 30days, 90daysResponse:
{
"summary": {
"site_id": 1,
"period": "7days",
"total_pageviews": 1000,
"unique_visitors": 500,
"total_sessions": 300,
"bounce_rate": 45.5,
"avg_session_duration": 120.5,
"top_pages": [["/", 500], ["/about", 200]],
"top_referrers": [["google.com", 300], ["direct", 200]],
"device_breakdown": {
"Desktop": 600,
"Mobile": 350,
"Tablet": 50
},
"browser_breakdown": {
"Chrome": 500,
"Firefox": 300,
"Safari": 200
},
"country_breakdown": {
"US": 400,
"UK": 200,
"DE": 100
}
},
"pageviews_over_time": [
{"date": "2026-04-22", "pageviews": 100},
{"date": "2026-04-23", "pageviews": 150}
],
"events_summary": [
["signup", 50],
["purchase", 25]
]
}
POST /api/track/pageview
Request Body:
{
"site_id": 1,
"api_key": "xyz789",
"url": "/about",
"title": "About Us",
"referrer": "https://google.com",
"user_agent": "Mozilla/5.0...",
"session_id": "abc123"
}
Response:
{
"status": "success"
}
POST /api/track/event
Request Body:
{
"site_id": 1,
"api_key": "xyz789",
"event_name": "signup",
"event_data": {
"plan": "pro"
},
"session_id": "abc123"
}
Response:
{
"status": "success"
}
POST /api/goals
Request Body:
{
"site_id": 1,
"name": "Newsletter Signup",
"description": "Track newsletter signups",
"goal_type": "event",
"target_value": "newsletter_signup"
}
Response:
{
"id": 1,
"site_id": 1,
"name": "Newsletter Signup",
"description": "Track newsletter signups",
"goal_type": "event",
"target_value": "newsletter_signup",
"created_at": "2026-04-29T12:00:00"
}
GET /api/goals/{site_id}
Response:
[
{
"id": 1,
"site_id": 1,
"name": "Newsletter Signup",
"description": "Track newsletter signups",
"goal_type": "event",
"target_value": "newsletter_signup",
"created_at": "2026-04-29T12:00:00"
}
]
All endpoints may return error responses in the following format:
{
"detail": "Error message"
}
200 OK: Request successful201 Created: Resource created successfully400 Bad Request: Invalid request data401 Unauthorized: Authentication required or invalid403 Forbidden: Access denied404 Not Found: Resource not found429 Too Many Requests: Rate limit exceeded500 Internal Server Error: Server errorThe API has rate limiting enabled:
Interactive API documentation is available at:
http://localhost:8000/docs
This provides a Swagger UI where you can test all endpoints directly.