GET /sites/$site/stats

Get a site's stats

Resource Information

   
Method GET
URL https://public-api.wordpress.com/rest/v1.1/sites/$site/stats
Requires authentication? Yes

Method Parameters

Parameter Type Description
$site (int|string) The site's id or domain

Query Parameters

Parameter Type Description
context (string)
display:
(default) Formats the output as HTML for display. Shortcodes are parsed, paragraph tags are added, etc..
edit:
Formats the output for editing. Shortcodes are left unparsed, significant whitespace is kept, etc..
http_envelope (bool)
false:
(default)
true:
Some environments (like in-browser JavaScript or Flash) block or divert responses with a non-200 HTTP status code. Setting this parameter will force the HTTP status code to always be 200. The JSON response is wrapped in an "envelope" containing the "real" HTTP status code and headers.
pretty (bool)
false:
(default)
true:
Output pretty JSON
meta (string) Optional. Loads data from the endpoints found in the 'meta' part of the response. Comma-separated list. Example: meta=site,likes
fields (string) Optional. Returns specified fields only. Comma-separated list. Example: fields=ID,title
callback (string) An optional JSONP callback function.

Response Parameters

Parameter Type Description
date (string) The most-recent day for which stats are returned
stats (array) Stats about the requested site
visits (array) Visits to the requested site

Resource Errors

These are the possible errors returned by this endpoint.

HTTP Code Error Identifier Error Message
404 invalid_blog This blog does not have Jetpack connected
404 invalid_blog This blog does not have the Stats module enabled
403 unauthorized User cannot access this private blog.
403 unauthorized User cannot access this restricted blog
403 unauthorized user cannot view stats

Example

curl \
 -H 'authorization: Bearer YOUR_API_TOKEN' \
 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/stats'
<?php
$options  = array (
  'http' => 
  array (
    'ignore_errors' => true,
    'header' => 
    array (
      0 => 'authorization: Bearer YOUR_API_TOKEN',
    ),
  ),
);

$context  = stream_context_create( $options );
$response = file_get_contents(
	'https://public-api.wordpress.com/rest/v1.1/sites/82974409/stats',
	false,
	$context
);
$response = json_decode( $response );
?>

Response

{
    "date": "2021-10-21",
    "stats": {
        "visitors_today": 0,
        "visitors_yesterday": 0,
        "visitors": 104,
        "views_today": 0,
        "views_yesterday": 0,
        "views_best_day": "2017-05-11",
        "views_best_day_total": 11,
        "views": 161,
        "comments": 6,
        "posts": 10,
        "followers_blog": 1,
        "followers_comments": 1,
        "comments_per_month": 0,
        "comments_most_active_recent_day": "2015-04-18 20:01:17",
        "comments_most_active_time": "06:00",
        "comments_spam": 4536,
        "categories": 17,
        "tags": 15,
        "shares": 3,
        "shares_facebook": 2,
        "shares_twitter": 1,
        "shares_press-this": 0
    },
    "visits": {
        "unit": "day",
        "fields": [
            "period",
            "views",
            "visitors"
        ],
        "data": [
            [
                "2021-09-22",
                0,
                0
            ],
            [
                "2021-09-23",
                0,
                0
            ],
            [
                "2021-09-24",
                0,
                0
            ],
            [
                "2021-09-25",
                0,
                0
            ],
            [
                "2021-09-26",
                0,
                0
            ],
            [
                "2021-09-27",
                0,
                0
            ],
            [
                "2021-09-28",
                0,
                0
            ],
            [
                "2021-09-29",
                0,
                0
            ],
            [
                "2021-09-30",
                0,
                0
            ],
            [
                "2021-10-01",
                0,
                0
            ],
            [
                "2021-10-02",
                0,
                0
            ],
            [
                "2021-10-03",
                0,
                0
            ],
            [
                "2021-10-04",
                0,
                0
            ],
            [
                "2021-10-05",
                0,
                0
            ],
            [
                "2021-10-06",
                0,
                0
            ],
            [
                "2021-10-07",
                0,
                0
            ],
            [
                "2021-10-08",
                0,
                0
            ],
            [
                "2021-10-09",
                0,
                0
            ],
            [
                "2021-10-10",
                0,
                0
            ],
            [
                "2021-10-11",
                0,
                0
            ],
            [
                "2021-10-12",
                0,
                0
            ],
            [
                "2021-10-13",
                0,
                0
            ],
            [
                "2021-10-14",
                0,
                0
            ],
            [
                "2021-10-15",
                0,
                0
            ],
            [
                "2021-10-16",
                0,
                0
            ],
            [
                "2021-10-17",
                0,
                0
            ],
            [
                "2021-10-18",
                0,
                0
            ],
            [
                "2021-10-19",
                0,
                0
            ],
            [
                "2021-10-20",
                0,
                0
            ],
            [
                "2021-10-21",
                0,
                0
            ]
        ]
    }
}