Title: API Stats
Author: Salar Gholizadeh
Published: <strong>14 Agosto 2019</strong>
Last modified: 11 Ottobre 2026

---

Ricerca i plugin

![](https://ps.w.org/wp-api-stats/assets/icon-256x256.png?rev=3739858)

# API Stats

 Di [Salar Gholizadeh](https://profiles.wordpress.org/salar6990/)

[Scarica](https://downloads.wordpress.org/plugin/wp-api-stats.2.0.zip)

 * [Dettagli](https://it.wordpress.org/plugins/wp-api-stats/#description)
 * [Recensioni](https://it.wordpress.org/plugins/wp-api-stats/#reviews)
 * [Sviluppo](https://it.wordpress.org/plugins/wp-api-stats/#developers)

 [Supporto](https://wordpress.org/support/plugin/wp-api-stats/)

## Descrizione

Do you use the WordPress REST API to serve apps, headless front ends or integrations?

API Stats records every REST API request to your site and shows you what is being
called, how often, how fast, and what fails.

#### Features

 * Records every REST route: WordPress core, WooCommerce and any other plugin or
   custom endpoint
 * Requests-over-time chart, broken down by HTTP method or by status (2xx / 3xx /
   4xx / 5xx)
 * Summary of requests, error rate, average and maximum response time
 * Routes table grouped by route pattern (e.g. `/wp/v2/posts/(?P<id>[\d]+)`) or 
   by exact path, with error counts and timings
 * Quick date ranges (today, yesterday, 7 and 30 days) or any custom range, with
   minute / hour / day / week resolution
 * Filter everything by route (contains or exact), HTTP method and status (e.g. 
   only errors); click a route to drill down
 * Configurable data retention, and a button to delete all recorded data
 * Developer hooks to skip requests or attach a readable label to them

Stats are under **Tools  API Stats**. Data is stored in your own database; nothing
is sent anywhere.

You can view this project on [GitHub](https://github.com/salar90/wp-api-stats).

## Screenshot

[⌊Stats page: filters, summary, requests over time by HTTP method, routes grouped
by route pattern, and data retention.⌉⌊Stats page: filters, summary, requests over
time by HTTP method, routes grouped by route pattern, and data retention.⌉[

Stats page: filters, summary, requests over time by HTTP method, routes grouped 
by route pattern, and data retention.

[⌊Drill-down: clicking a route filters the whole page. Here a failing endpoint, 
with the chart broken down by status.⌉⌊Drill-down: clicking a route filters the 
whole page. Here a failing endpoint, with the chart broken down by status.⌉[

Drill-down: clicking a route filters the whole page. Here a failing endpoint, with
the chart broken down by status.

[⌊Routes by exact path, with readable labels added through the sg_api_stats_label
filter.⌉⌊Routes by exact path, with readable labels added through the sg_api_stats_label
filter.⌉[

Routes by exact path, with readable labels added through the sg_api_stats_label 
filter.

## FAQ

### How long is data kept?

30 days by default. Change it under Tools  API Stats  Stored data. Set it to 0 to
keep data forever (the page shows how big the table is). Old events are removed 
hourly. Lowering the number deletes older events right away, after a confirmation
that tells you how many; deleted events can’t be restored by raising the number 
again. Developers can also set it in code:

    ```
    add_filter( 'sg_api_stats_retention_days', function () { return 90; } );
    ```

### How do I delete all recorded data?

Use the “Delete all data” button under Tools  API Stats  Stored data. Recording 
continues afterwards. Uninstalling the plugin also removes its table and settings.

### Can I stop some requests from being recorded?

Yes, with the `sg_api_stats_should_record` filter. Return false to skip a request:

    ```
    add_filter( 'sg_api_stats_should_record', function ( $record, $request ) {
        return 0 !== strpos( $request->get_route(), '/wp/v2/' );
    }, 10, 2 );
    ```

### Can I show a readable name next to routes like /myapi/doc/123?

Yes. Return a label from the `sg_api_stats_label` filter. It is stored with the 
request and shown in the routes table when grouping by exact path:

    ```
    add_filter( 'sg_api_stats_label', function ( $label, $request ) {
        if ( preg_match( '#^/myapi/doc/(\d+)$#', $request->get_route(), $m ) ) {
            return get_the_title( (int) $m[1] );
        }
        return $label;
    }, 10, 2 );
    ```

### What does “By pattern” mean in the routes table?

Requests are grouped by the registered route they matched, so `/wp/v2/posts/1`, `/
wp/v2/posts/2`, … appear as one row `/wp/v2/posts/(?P<id>[\d]+)` with the number
of distinct paths. Switch to “By exact path” to see each URL separately. Requests
that matched no route (404) are always shown by path.

### Which timezone is used?

Your site’s timezone (Settings  General). Durations are measured from the start 
of REST API handling until the response is sent, in milliseconds.

## Recensioni

![](https://secure.gravatar.com/avatar/233b74e166b2c106d719fc5a25e28f8152bd627e20ba74f50549d0fa1fc30c38?
s=60&d=retro&r=g)

### 󠀁[Still work!](https://wordpress.org/support/topic/still-work-7/)󠁿

 [bbombb](https://profiles.wordpress.org/bbombb/) 29 Agosto 2023 1 risposta

The menu located under tools and everything still work perfectly.

![](https://secure.gravatar.com/avatar/02a76d95b36cbc866cf2652b1a0739943346028e0564ba8735ed59744c41cfe7?
s=60&d=retro&r=g)

### 󠀁[Nice work!](https://wordpress.org/support/topic/nice-work-484/)󠁿

 [con](https://profiles.wordpress.org/conschneider/) 27 Settembre 2020 1 risposta

Gives a great overview for app tracking :).

![](https://secure.gravatar.com/avatar/b4b895866395af144ae70ca1b97fe506a52502794688de0ed5646805f870591c?
s=60&d=retro&r=g)

### 󠀁[Simple and awesome!](https://wordpress.org/support/topic/simple-and-awesome-57/)󠁿

 [eCardWidget.com](https://profiles.wordpress.org/timsayshey/) 7 Gennaio 2020

Saved me from having to come up with something to track my API usage. Works great!
Thanks!

 [ Leggi tutte le recensioni di 3 ](https://wordpress.org/support/plugin/wp-api-stats/reviews/)

## Contributi e sviluppo

“API Stats” è un software open source. Le persone che hanno contribuito allo sviluppo
di questo plugin sono indicate di seguito.

Collaboratori

 *   [ Salar Gholizadeh ](https://profiles.wordpress.org/salar6990/)

[Traduci “API Stats” nella tua lingua.](https://translate.wordpress.org/projects/wp-plugins/wp-api-stats)

### Ti interessa lo sviluppo?

[Esplora il codice](https://plugins.trac.wordpress.org/browser/wp-api-stats/) segui
il [repository SVN](https://plugins.svn.wordpress.org/wp-api-stats/), segui il [log delle modifiche](https://plugins.trac.wordpress.org/log/wp-api-stats/)
tramite [RSS](https://plugins.trac.wordpress.org/log/wp-api-stats/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

#### 2.0

 * New: redesigned stats page with summary cards, quick date ranges and a sortable
   routes table
 * New: filter the whole page (cards, chart and table) by route, method and status,
   e.g. “errors only”; active filters are shown as removable chips and kept in the
   URL
 * New: click a route in the table to drill down into it
 * New: chart breakdown by status class (2xx/3xx/4xx/5xx) in addition to HTTP method
 * New: routes grouped by registered route pattern, so /posts/1, /posts/2, … count
   as one route (switchable to exact paths)
 * New: error counts and maximum duration per route
 * New: configurable data retention (0 = keep forever) and a “Delete all data” button;
   lowering retention asks for confirmation and shows how many events will be deleted
 * New: developer filters sg_api_stats_should_record, sg_api_stats_label and sg_api_stats_retention_days
 * Fix: event IDs could overflow after about 8.4 million recorded requests, which
   stopped recording
 * Performance: index on the event time column; old events are deleted in batches
 * Database schema is upgraded automatically on update
 * Chart.js updated from 2.8 to 4.5

#### 1.5

 * Security: escape recorded routes and methods on the stats page (fixes stored 
   XSS via crafted REST URLs)
 * Security: strictly validate date and point filters; all SQL queries now use prepared
   statements
 * Faster stats page: chart data comes from a single grouped query instead of one
   query per point
 * Fix: date filters now use the site timezone consistently for both the chart and
   the routes table
 * Filters use the URL (GET), so filtered views can be bookmarked and reloaded
 * Routes table limited to the top 200 routes
 * Uninstalling the plugin now removes its database table, option and scheduled 
   event
 * Text domain changed to wp-api-stats to match the plugin slug (enables wordpress.
   org translations)
 * Requires WordPress 5.3+ and PHP 7.2+
 * Tested with WordPress 7.1

#### 1.4

 * Update plugin description
 * Fix Input sanitization
 * Add Feature to display size of data stored in database for API events
 * Test with WP 6.4.1

## Meta

 *  Versione **2.0**
 *  Ultimo aggiornamento **2 settimane fa**
 *  Installazioni attive **80+**
 *  Versione WordPress ** 5.3 o superiore **
 *  Testato fino alla versione **7.1.3**
 *  Versione PHP ** 7.2 o superiore **
 *  Lingua
 * [English (US)](https://wordpress.org/plugins/wp-api-stats/)
 * Tag
 * [api](https://it.wordpress.org/plugins/tags/api/)[monitoring](https://it.wordpress.org/plugins/tags/monitoring/)
   [performance](https://it.wordpress.org/plugins/tags/performance/)[rest-api](https://it.wordpress.org/plugins/tags/rest-api/)
   [statistics](https://it.wordpress.org/plugins/tags/statistics/)
 *  [Visualizzazione avanzata](https://it.wordpress.org/plugins/wp-api-stats/advanced/)

## Valutazioni

 5 su 5 stelle.

 *  [  3 recensioni a 5-stelle     ](https://wordpress.org/support/plugin/wp-api-stats/reviews/?filter=5)
 *  [  0 recensioni a 4-stelle     ](https://wordpress.org/support/plugin/wp-api-stats/reviews/?filter=4)
 *  [  0 recensioni a 3-stelle     ](https://wordpress.org/support/plugin/wp-api-stats/reviews/?filter=3)
 *  [  0 recensioni a 2-stelle     ](https://wordpress.org/support/plugin/wp-api-stats/reviews/?filter=2)
 *  [  0 recensioni a 1-stelle     ](https://wordpress.org/support/plugin/wp-api-stats/reviews/?filter=1)

[La tua recensione](https://wordpress.org/support/plugin/wp-api-stats/reviews/#new-post)

[Vedi tutte le recensioni](https://wordpress.org/support/plugin/wp-api-stats/reviews/)

## Collaboratori

 *   [ Salar Gholizadeh ](https://profiles.wordpress.org/salar6990/)

## Supporto

Hai qualcosa da dire? Ti serve aiuto?

 [Chiedi nel forum di supporto](https://wordpress.org/support/plugin/wp-api-stats/)