DataDad.

Analytics API

Read your visitors, page views and link clicks from your own server with a secret key. Create a key, make the first request, and learn the limits.

Updated

The stats API gives your server the same numbers as the DataDad dashboard: visitors, page views, visits, bounce rate, visit duration and link clicks. Use it to show statistics in your own product, or to copy them into another tool.

Create an API key

  1. Open the app in DataDad and select Settings.
  2. Under Stats API, enter a name for the key, such as Production server.
  3. Select Create API key.
  4. Copy the key. DataDad shows it only once.

Each key reads one app. An app can have up to 10 keys. To stop a key, select Revoke next to it. Requests with a revoked key fail at once.

Make the first request

Send the key in the Authorization header. This request gets the totals for the last 30 days:

curl "https://data.dad/api/v1/stats/summary?range=30d" \
  -H "Authorization: Bearer $DATADAD_API_KEY"
const response = await fetch('https://data.dad/api/v1/stats/summary?range=30d', {
  headers: { Authorization: `Bearer ${process.env.DATADAD_API_KEY}` },
});
const stats = await response.json();
console.log(stats.visitors, stats.pageviews);
import os, requests

stats = requests.get(
    "https://data.dad/api/v1/stats/summary",
    params={"range": "30d"},
    headers={"Authorization": f"Bearer {os.environ['DATADAD_API_KEY']}"},
    timeout=30,
).json()
print(stats["visitors"], stats["pageviews"])
$context = stream_context_create(['http' => [
    'header' => 'Authorization: Bearer ' . getenv('DATADAD_API_KEY'),
]]);
$stats = json_decode(file_get_contents('https://data.dad/api/v1/stats/summary?range=30d', false, $context), true);
echo $stats['visitors'];

The response:

{
  "tenant": null,
  "range": { "from": 1789430400, "to": 1792022400, "previous_from": 1786838400, "previous_to": 1789430400 },
  "visitors": 1840, "pageviews": 2610, "link_clicks": 912,
  "visits": 2093, "bounce_rate": 0.71, "visit_duration": 38,
  "previous": { "visitors": 1502, "pageviews": 2177, "link_clicks": 701, "visits": 1730, "bounce_rate": 0.69, "visit_duration": 41 }
}

Choose a period

Every endpoint takes range. The default is 30d.

ValuePeriod
1h, 24hThe last hour or the last 24 hours
7d, 30d, 90dThe last 7, 30 or 90 days
1y, 3yThe last year or the last 3 years
today, yesterdayThe current or the previous UTC day
wtd, mtd, ytdThe week, month or year to date

For other dates, send from and to as YYYY-MM-DD instead of range. Both days are included. The period can be up to 3 years long. All days and times are UTC. Timestamps in responses are Unix seconds.

Errors

An error response has an HTTP status and a JSON body with a message and a code:

{ "error": "This API key is not valid.", "code": "unauthorized" }
StatusCodeWhat to do
400invalid_requestCorrect the parameter that the message names.
401unauthorizedSend a valid key that was not revoked.
429rate_limitedYour app used its requests for this minute. Wait for the time in the Retry-After header.
429busyMany requests for your app are running now. Wait for the time in the Retry-After header.
503unavailableTry again after the time in Retry-After.

Limits and caching

Next steps