Skip to main content

Analytics API

Query analytics data programmatically. Requires authentication via JWT token or API key (X-API-Key).

Overview

The Analytics API provides real-time and historical analytics data for campaigns, affiliates, and performance metrics. Two API versions are available:

  • Legacy (Deprecated): /api/analytics/* — for backward compatibility
  • Versioned: /api/v1/analytics/* — recommended for new integrations

Click Summary

Get aggregated click data for a date range:

curl "https://api.affilync.com/api/analytics/overview?time_range=last_30_days" \
-H "Authorization: Bearer YOUR_TOKEN"

Query Parameters:

ParameterTypeRequiredDescription
start_datestringYesStart date (YYYY-MM-DD)
end_datestringYesEnd date (YYYY-MM-DD)
campaign_idstringNoFilter by campaign
affiliate_idstringNoFilter by affiliate
granularitystringNohourly, daily (default), weekly, monthly

Response (200):

{
"time_range": "2026-03-01 to 2026-03-21",
"clicks": 48210,
"conversions": 2105,
"revenue": 52625.00,
"conversion_rate": 4.37,
"summary": {
"total_clicks": 48210,
"unique_clicks": 35890,
"total_conversions": 2105,
"conversion_rate": 4.37,
"total_revenue": 52625.00
}
}

Conversion Report

curl "https://api.affilync.com/api/v1/analytics/conversions?start_date=2026-03-01&end_date=2026-03-21" \
-H "Authorization: Bearer YOUR_TOKEN"

Query Parameters:

ParameterTypeDescription
start_datestringStart date (YYYY-MM-DD)
end_datestringEnd date (YYYY-MM-DD)
statusstringpending, approved, rejected, paid
campaign_idstringFilter by campaign
affiliate_idstringFilter by affiliate

Response (200):

{
"data": [
{
"id": "conv_j3k4l5",
"campaign_id": "camp_abc123",
"affiliate_id": "aff_m6n7o8",
"link_id": "lnk_x7kQ2mNp",
"type": "sale",
"status": "approved",
"commission": "25.00",
"order_value": "149.99",
"click_to_conversion_seconds": 3842,
"converted_at": "2026-03-15T14:22:00Z"
}
],
"meta": {
"page": 1,
"per_page": 20,
"total": 2105
}
}

Campaign Performance

curl "https://api.affilync.com/api/analytics/campaigns?time_range=last_30_days" \
-H "Authorization: Bearer YOUR_TOKEN"

Returns per-campaign aggregates: clicks, conversions, revenue, commission, and performance metrics.

Response (200):

{
"data": [
{
"campaign_id": "camp_abc123",
"name": "Summer Sale 2026",
"clicks": 12500,
"conversions": 425,
"revenue": 15750.00,
"commission": 1575.00,
"conversion_rate": 3.4,
"roi": 2.5
}
],
"summary": {
"total_campaigns": 5,
"active_campaigns": 3,
"total_clicks": 48210,
"total_conversions": 2105
}
}

Top Performers

curl "https://api.affilync.com/api/v1/analytics/top-performers?entity_type=affiliates&start_date=2026-03-01&end_date=2026-03-21&limit=10" \
-H "Authorization: Bearer YOUR_TOKEN"

Query Parameters:

ParameterTypeDescription
entity_typestringaffiliates or campaigns
limitintegerMaximum results (default: 10, max: 100)
start_datestringStart date (YYYY-MM-DD)
end_datestringEnd date (YYYY-MM-DD)

Response (200):

{
"entity_type": "affiliates",
"performers": [
{
"id": "aff_m6n7o8",
"name": "Jane Doe",
"clicks": 5200,
"conversions": 312,
"revenue": 7800.00,
"epc": 1.50
}
],
"summary": {
"total_performers": 125,
"total_revenue": 52625.00,
"avg_conversion_rate": 4.37
}
}

Revenue Analytics

curl "https://api.affilync.com/api/v1/analytics/revenue?start_date=2026-03-01&end_date=2026-03-21&granularity=daily" \
-H "Authorization: Bearer YOUR_TOKEN"

Query Parameters:

ParameterTypeDescription
granularitystringhourly, daily (default), weekly, monthly
currencystringCurrency code (USD, EUR, GBP, etc.)

Response (200):

{
"granularity": "daily",
"currency": "USD",
"data": [
{
"date": "2026-03-15",
"revenue": 2550.00,
"commissions": 255.00,
"conversions": 102,
"clicks": 2340
}
],
"summary": {
"total_revenue": 52625.00,
"total_commissions": 5262.50,
"avg_order_value": 24.98
}
}

Geographic Analytics

curl "https://api.affilync.com/api/analytics/geographic?granularity=country&time_range=last_30_days" \
-H "Authorization: Bearer YOUR_TOKEN"

Query Parameters:

ParameterTypeDescription
granularitystringcountry, region, city

Response (200):

{
"granularity": "country",
"data": [
{
"country": "US",
"clicks": 35000,
"conversions": 1820,
"revenue": 42150.00,
"conversion_rate": 5.2
},
{
"country": "CA",
"clicks": 8200,
"conversions": 245,
"revenue": 8475.00,
"conversion_rate": 2.98
}
],
"summary": {
"total_countries": 42,
"top_country": "US",
"total_clicks": 48210,
"total_conversions": 2105
}
}

Metric Snapshots (Time Series)

curl -X POST https://api.affilync.com/api/analytics/metrics/query \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"entity_type": "campaign",
"entity_id": "camp_abc123",
"metric_names": ["clicks", "conversions", "revenue"],
"granularity": "daily",
"start_date": "2026-03-01",
"end_date": "2026-03-21"
}'

Response (200):

{
"data": [
{
"timestamp": "2026-03-15T00:00:00Z",
"entity_type": "campaign",
"entity_id": "camp_abc123",
"metrics": {
"clicks": 2340,
"conversions": 102,
"revenue": 2550.00
}
}
]
}

Data Export

Generate a downloadable analytics report:

curl -X POST https://api.affilync.com/api/analytics/export/async/campaign_metrics \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"campaign_id": "camp_abc123",
"start_date": "2026-03-01",
"end_date": "2026-03-21",
"format": "csv"
}'

Request Body:

FieldTypeRequiredDescription
campaign_idstringYes (for campaign exports)Campaign to export
affiliate_idstringYes (for affiliate exports)Affiliate to export
start_datestringYesStart date (YYYY-MM-DD)
end_datestringYesEnd date (YYYY-MM-DD)
formatstringYescsv, excel, or pdf
granularitystringNohour, day (default), week, month

Response (202 - Accepted):

{
"job_id": "exp_p9q0r1",
"export_id": "exp_p9q0r1",
"status": "processing",
"download_url": null,
"created_at": "2026-03-21T10:30:00Z"
}

Check Export Status

curl https://api.affilync.com/api/analytics/export/async/jobs/exp_p9q0r1 \
-H "Authorization: Bearer YOUR_TOKEN"

Response (200):

{
"job_id": "exp_p9q0r1",
"status": "completed",
"download_url": "https://downloads.affilync.com/exports/exp_p9q0r1.csv",
"format": "csv",
"rows_processed": 2105,
"created_at": "2026-03-21T10:30:00Z",
"completed_at": "2026-03-21T10:35:00Z"
}

Download Exported File

curl https://api.affilync.com/api/analytics/export/download/exp_p9q0r1 \
-H "Authorization: Bearer YOUR_TOKEN" \
-o analytics_export.csv

Real-Time Analytics

Get live metrics updated every minute:

curl "https://api.affilync.com/api/analytics/dashboard-summary?time_range=last_7_days" \
-H "Authorization: Bearer YOUR_TOKEN"

Response (200):

{
"timestamp": "2026-03-21T14:22:00Z",
"clicks_last_hour": 1250,
"conversions_last_hour": 48,
"revenue_last_hour": 1895.50,
"active_campaigns": 12,
"active_affiliates": 89
}

Authentication

All analytics endpoints require:

  • Authentication: A valid JWT access token (Authorization: Bearer …) or an API key (X-API-Key)
  • Access: You can only read analytics for your own account's campaigns, links, and affiliates
  • Rate Limit: 1,000 requests/hour per token

Error Handling

The API returns standard HTTP status codes:

CodeMeaningExample
200SuccessData returned successfully
202AcceptedAsync export job queued
400Bad RequestInvalid date format or missing parameter
401UnauthorizedMissing or invalid authentication token
403ForbiddenInsufficient permissions (wrong scope)
404Not FoundCampaign, affiliate, or export job not found
429Rate LimitedToo many requests in short time
500Server ErrorTemporary service issue

Error Response:

{
"detail": "Campaign not found",
"status": 404,
"error_code": "CAMPAIGN_NOT_FOUND"
}

Pagination

Endpoints returning lists support pagination:

curl "https://api.affilync.com/api/v1/analytics/conversions?page=2&per_page=50" \
-H "Authorization: Bearer YOUR_TOKEN"

Query Parameters:

ParameterTypeDefaultMax
pageinteger1N/A
per_pageinteger20100

Meta in Response:

{
"meta": {
"page": 2,
"per_page": 50,
"total": 2105,
"total_pages": 43
}
}

Next Steps