Analytics API
Get click statistics, geographic data, and referrer information for your links.
The Analytics API returns the same aggregated click metrics you see on a link's detail page in the dashboard — but in machine-readable JSON, so you can pipe them into your own reporting, BI dashboards, or scheduled exports. Every response is scoped to a single short link, identified by its short code, and reflects all click events recorded within your plan's retention window.
Metrics are privacy-preserving aggregates. The API exposes totals and breakdowns (countries, referrers, devices, browsers) rather than individual visitor records, so there are no raw IP addresses or personally identifying fields in the payload.
/api/v1/stats/:codeGet detailed click statistics for a link by its short code.
analytics:read + links:read(both required — the response includes link metadata, so the key must also be allowed to read links).Path Parameters
| Name | Type | Required | Description |
|---|---|---|---|
code | string | Yes | The short code of the link to fetch stats for (e.g. my-link). |
Request
curl https://trimlink.co/api/v1/stats/my-link \
-H "Authorization: Bearer tk_live_your_api_key"Response
{
"success": true,
"data": {
"totalClicks": 1542,
"uniqueClicks": 1203,
"clicksByDay": [
{ "date": "2026-01-30", "clicks": 45 },
{ "date": "2026-01-29", "clicks": 62 },
{ "date": "2026-01-28", "clicks": 38 }
],
"topCountries": [
{ "country": "US", "clicks": 523 },
{ "country": "GB", "clicks": 234 },
{ "country": "DE", "clicks": 156 }
],
"topReferrers": [
{ "referrer": "twitter.com", "clicks": 312 },
{ "referrer": "direct", "clicks": 456 },
{ "referrer": "google.com", "clicks": 189 }
],
"devices": {
"mobile": 823,
"desktop": 612,
"tablet": 107
},
"browsers": {
"Chrome": 892,
"Safari": 423,
"Firefox": 227
}
}
}Response Fields
| Field | Type | Description |
|---|---|---|
totalClicks | number | Total click count |
uniqueClicks | number | Unique visitors |
clicksByDay | array | Daily click breakdown |
topCountries | array | Top countries by clicks |
topReferrers | array | Top referrer sources |
devices | object | Device type breakdown |
browsers | object | Browser breakdown |
Errors
This endpoint returns the standard error response format. The most common failures are:
| Code | When it happens |
|---|---|
401 | Missing or invalid API key. |
403 | Key is missing the analytics:read or links:read scope (both are required), or the plan does not include API analytics. |
404 | No link exists for the supplied short code, or it belongs to another account. |
Usage Notes
- Click data is aggregated and may lag real-time clicks by a short interval — treat counts as eventually consistent rather than instantaneous.
- The
clicksByDaywindow and overall history are bounded by your plan's retention (see below); older buckets drop off the array once they fall outside the window. uniqueClicksis a best-effort de-duplication and will always be less than or equal tototalClicks.- Requests count against your rate limit. Cache results on your side if you poll frequently.
Plan Requirements
Analytics data retention varies by plan:
- Growth: 30 days of detailed analytics
- Teams: 90 days of detailed analytics
- Enterprise: Unlimited retention