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.

GET/api/v1/stats/:code

Get detailed click statistics for a link by its short code.

Scopes: analytics:read + links:read(both required — the response includes link metadata, so the key must also be allowed to read links).

Path Parameters

NameTypeRequiredDescription
codestringYesThe 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

200Response
{
  "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

FieldTypeDescription
totalClicksnumberTotal click count
uniqueClicksnumberUnique visitors
clicksByDayarrayDaily click breakdown
topCountriesarrayTop countries by clicks
topReferrersarrayTop referrer sources
devicesobjectDevice type breakdown
browsersobjectBrowser breakdown

Errors

This endpoint returns the standard error response format. The most common failures are:

CodeWhen it happens
401Missing or invalid API key.
403Key is missing the analytics:read or links:read scope (both are required), or the plan does not include API analytics.
404No 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 clicksByDay window and overall history are bounded by your plan's retention (see below); older buckets drop off the array once they fall outside the window.
  • uniqueClicks is a best-effort de-duplication and will always be less than or equal to totalClicks.
  • 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