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": "2017-03-23",
    "stats": {
        "visitors_today": 0,
        "visitors_yesterday": 0,
        "visitors": 34,
        "views_today": 0,
        "views_yesterday": 0,
        "views_best_day": "2015-08-06",
        "views_best_day_total": 7,
        "views": 51,
        "comments": 6,
        "posts": 8,
        "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": 234,
        "categories": 17,
        "tags": 15,
        "shares": 0,
        "shares_twitter": 0,
        "shares_press-this": 0,
        "shares_google-plus-1": 0,
        "shares_facebook": 0
    },
    "visits": {
        "unit": "day",
        "fields": [
            "period",
            "views",
            "visitors"
        ],
        "data": [
            [
                "2017-02-22",
                0,
                0
            ],
            [
                "2017-02-23",
                0,
                0
            ],
            [
                "2017-02-24",
                0,
                0
            ],
            [
                "2017-02-25",
                0,
                0
            ],
            [
                "2017-02-26",
                0,
                0
            ],
            [
                "2017-02-27",
                0,
                0
            ],
            [
                "2017-02-28",
                0,
                0
            ],
            [
                "2017-03-01",
                0,
                0
            ],
            [
                "2017-03-02",
                0,
                0
            ],
            [
                "2017-03-03",
                0,
                0
            ],
            [
                "2017-03-04",
                0,
                0
            ],
            [
                "2017-03-05",
                0,
                0
            ],
            [
                "2017-03-06",
                0,
                0
            ],
            [
                "2017-03-07",
                0,
                0
            ],
            [
                "2017-03-08",
                0,
                0
            ],
            [
                "2017-03-09",
                0,
                0
            ],
            [
                "2017-03-10",
                0,
                0
            ],
            [
                "2017-03-11",
                0,
                0
            ],
            [
                "2017-03-12",
                0,
                0
            ],
            [
                "2017-03-13",
                0,
                0
            ],
            [
                "2017-03-14",
                0,
                0
            ],
            [
                "2017-03-15",
                0,
                0
            ],
            [
                "2017-03-16",
                0,
                0
            ],
            [
                "2017-03-17",
                0,
                0
            ],
            [
                "2017-03-18",
                0,
                0
            ],
            [
                "2017-03-19",
                2,
                1
            ],
            [
                "2017-03-20",
                0,
                0
            ],
            [
                "2017-03-21",
                0,
                0
            ],
            [
                "2017-03-22",
                0,
                0
            ],
            [
                "2017-03-23",
                0,
                0
            ]
        ]
    }
}