Make a key #
In any site's Settings, under API keys, name a key and create it. The key is shown once: copy it then, because we keep only a hash of it. A key reads the stats of every site on your account and cannot change anything. Delete it and it stops working at once. An account can hold 10 keys.
Send a request #
Put the key in the Authorization header:
curl -H "Authorization: Bearer adl_YOUR_KEY" "https://adlens.adlens-trial.workers.dev/api/v1/stats/SITE_ID/pages?period=30d"GET /api/v1/siteslists your sites with their ids.GET /api/v1/stats/SITE_ID/REPORTanswers one report:overview,pages,countries,devices,sources,events,ads,realtimeorsite.
Reports take the same query as the dashboard: period is today, 7d, 30d, 90d or custom with from and to as YYYY-MM-DD. Filter with page, country (two letters, lower case), device (mobile, tablet, desktop), os, browser or source.
Send events #
POST /api/v1/events with a key records a pageview or an event from your server, with the visitor's IP address and browser if you have them. It answers 202. The body and an example are in Events from your server.
Limits #
Each key can make 600 requests in each clock hour. Past that the API answers 429 with a Retry-After header in seconds. Every answer carries x-ratelimit-limit and x-ratelimit-remaining.
Errors #
- 401
bad_key: the key is missing, wrong or deleted. - 404: the site belongs to another account, or the report does not exist.
- 429
rate_limited: wait theretry_afterseconds.
About the numbers #
They are the same numbers the dashboard shows. Revenue is an estimate until a network is connected, and every answer with revenue says "revenue_source": "estimate". Counts are estimates too when traffic is heavy, because the store samples rows: see Open numbers.
CSV #
Add .csv to a grouped report (pages, countries, devices, sources, events, goals) to get its rows as a spreadsheet file, up to 1,000 rows, with the same columns as the JSON. Every table in the dashboard has an Export CSV button that does the same for the period and filters on screen.
All sites #
GET /api/stats/all/overview answers one row per site and the totals. Days are counted in UTC for this report.