WordPress Analytics API: Build Your Own Traffic Report in an Afternoon
Dashboards are for looking. An API is for the report you actually send: your sites, your columns, no screenshots.
On this page
A WordPress analytics API turns the dashboard you look at into data you can use: a JSON answer for every report, pulled by a script or a sheet whenever you want. The point is the report you actually send, with your sites and your columns, generated on a schedule instead of assembled from screenshots. This post uses the DevDome Stats API as the worked example, because we make it; the structure applies to any analytics API that exposes its reports.
What the API gives you
The DevDome Stats API mirrors the dashboard one report per endpoint. The groups that matter for a report:
- Account and sites: who you are, which sites are on the account and whether each is verified.
- Traffic: headline stats for a window with the previous window alongside, a daily time series, the last 24 hours by hour, per-page traffic with page health, referrers, redirects, keywords, products and UTM campaigns.
- Audience: countries, regions, cities, devices, browsers and operating systems.
- Visitors: recent visits with their step-by-step paths, the paths of people who entered on one page, and who is active right now.
- Bots: every detected bot with its reason, and detection-category totals.
- Site health: uptime, response times, TLS and DNS checks, incidents and alerts.
- Export: the raw analytics for a window as CSV.
Every call takes a site and a window, either a number of days or a from and to date. Everything returns JSON except the export, which returns CSV.
Keys, headers and limits
You create a key in the dashboard and send it as a bearer token in the Authorization header. The key is the credential: anyone who has it can read your data, so keep it in a password manager or an environment variable and revoke it when the use ends.
The rate limit is 60 requests per minute per key, with a 429 response and a retry-after header when you exceed it. For a portfolio of fifty sites with three calls each, that is a two- or three-minute loop with a short pause. Large windows should be paged month by month; the export endpoint with no window streams your whole retained history in one response, which can be tens of megabytes.
The first report: three calls
A monthly report that beats most agency decks needs three endpoints per site.
Headline stats. The stats endpoint returns the window and the previous window together: human pageviews, visits, visitors, bounce rate and session duration, so the change column is a subtraction you do yourself.
Top pages. The pages endpoint with a limit gives the top N pages with their traffic and a health status from the 404 prober, plus the total page count and the number of broken pages. That last number is the one clients notice.
Countries. One row per country. Pair it with the bots endpoint if the client is seeing a suspicious spike from somewhere.
Three calls, three tables, one site. Loop over the sites endpoint for the rest.
Read the counting rules first
The API documents how each number is counted, and the rules matter when you compare with other tools:
- Visits are sessions with a 30-minute gap rule.
- Visitors are every distinct identity seen in the window, including people who only passed through a tracked redirect link, so on redirect-heavy sites visitors can exceed pageviews.
- New visitors only mean something when the site recognises returning visitors. With cookieless tracking the visitor id rotates daily, so new visitors is reported as null when the dashboard’s cookieless switch is on. If new visitors is almost equal to visitors, the tracker and the dashboard switch disagree; fix the setting rather than report the number.
- Bots are excluded from human counts and reported separately.
Google Analytics will show more visitors. The gap is the bot share plus hits that blockers removed, which the API’s server-side click capture and bot split account for.
From script to sheet
For a one-person operation, a spreadsheet with a fetch function per cell is enough: one row per site, columns for the three calls. For an agency, a short script that runs on the first of the month, writes a CSV per client and emails it is an afternoon’s work in any language with an HTTP library.
Two habits keep it reliable. Handle the 429 by waiting the retry-after seconds and continuing. And store the raw JSON responses alongside the report, so a question about a number three months later has an answer.
Adding sites and health to the same report
Two endpoint groups are worth adding once the basic report works. The sites endpoints let the script manage the portfolio as well as read it: list every site with its verification state, add a site and get back the verification file it needs, and remove one when a client leaves. The health endpoints turn the report into an operations summary: uptime and response times for the window, TLS and DNS checks, and the incidents list with start and end times, paged by the started_at of the last row. A monthly client report that shows traffic, top pages, broken pages and downtime on one sheet answers most questions before they are asked.
When an assistant is the client
The same data is available to AI tools through the DevDome MCP server, which exposes ten tools mapped one-to-one to dashboard reports. If you would rather ask “which of my sites lost traffic last week” than write the loop, that is the route, with the same key and the same limits.
Either way the dashboard stays for looking. The report you send comes from the API, in the shape you chose, on the day you chose.
Disclosure: DevDome publishes this blog and makes the products it mentions. We describe what they do rather than promise results.
Key takeaways
- A stats API gives you the same numbers as the dashboard as JSON, so a script or a sheet can pull them on a schedule.
- Start with three calls: headline stats, top pages and countries. That is a full monthly report.
- Read the counting rules before you compare numbers: visits, visitors and new visitors mean specific things.
- Keys are secrets. One key per use, revoked when the use ends, never in a public repository.
- Respect the rate limit and page large windows month by month; the export endpoint streams the whole history.
Sources
- DevDome Stats API OpenAPI specification : the machine-readable description of every endpoint
- MDN: Authorization header : how bearer tokens are sent
- MDN: 429 Too Many Requests : what a rate limit response means and the retry-after header
Links last checked October 17, 2026.
Frequently asked questions
Do I need to be a developer to use an analytics API?
Not really. A sheet function that fetches a URL with a header, or a ten-line script, is enough for a report. The hard part is choosing the columns, not the code.
What is an API key and where do I keep it?
A long random string that identifies your account to the API. Keep it in a password manager or an environment variable, never in a shared document or a public repository. If it leaks, revoke it and make a new one.
Why does the API show fewer visitors than Google Analytics?
Because it separates humans from bots and does not count the bot share as visitors, and because server-side click capture and cookieless tracking count differently. Read the counting rules in the docs before comparing.
Can I pull data for all my sites at once?
Call the sites endpoint for the list, then loop over it calling stats for each. Stay inside the rate limit, which is 60 requests per minute per key on the DevDome API, and you can cover a large portfolio in a minute or two.