GET /sites/$site/stats/visits

View and visitor counts for a site

Resource URL

Type URL and Format
GET https://public-api.wordpress.com/rest/v1/sites/$site/stats/visits

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
callback (string) An optional JSONP callback function.
unit (string) One of: day, week or month Default: 'day'.
quantity (int) number of units to return Default: 30.
date (string) limit the chart data to visits earlier than requested date

Example

cURL

curl \
 -H 'authorization: Bearer YOUR_API_TOKEN' \
 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.com/stats/visits'

PHP

<?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/sites/example.wordpress.com/stats/visits',
  false,
  $context
);
$response = json_decode( $response );

?>

Response Body

{
    "unit": "day",
    "fields": [
        "period",
        "views",
        "visitors"
    ],
    "data": [
        [
            "2014-03-18",
            61,
            38
        ],
        [
            "2014-03-19",
            62,
            39
        ],
        [
            "2014-03-20",
            67,
            36
        ],
        [
            "2014-03-21",
            57,
            38
        ],
        [
            "2014-03-22",
            59,
            35
        ],
        [
            "2014-03-23",
            42,
            33
        ],
        [
            "2014-03-24",
            61,
            38
        ],
        [
            "2014-03-25",
            48,
            35
        ],
        [
            "2014-03-26",
            87,
            52
        ],
        [
            "2014-03-27",
            63,
            40
        ],
        [
            "2014-03-28",
            47,
            30
        ],
        [
            "2014-03-29",
            52,
            35
        ],
        [
            "2014-03-30",
            63,
            36
        ],
        [
            "2014-03-31",
            60,
            35
        ],
        [
            "2014-04-01",
            65,
            31
        ],
        [
            "2014-04-02",
            59,
            39
        ],
        [
            "2014-04-03",
            48,
            29
        ],
        [
            "2014-04-04",
            83,
            54
        ],
        [
            "2014-04-05",
            64,
            36
        ],
        [
            "2014-04-06",
            50,
            35
        ],
        [
            "2014-04-07",
            77,
            55
        ],
        [
            "2014-04-08",
            93,
            51
        ],
        [
            "2014-04-09",
            79,
            44
        ],
        [
            "2014-04-10",
            79,
            35
        ],
        [
            "2014-04-11",
            64,
            45
        ],
        [
            "2014-04-12",
            64,
            40
        ],
        [
            "2014-04-13",
            77,
            40
        ],
        [
            "2014-04-14",
            100,
            57
        ],
        [
            "2014-04-15",
            103,
            58
        ],
        [
            "2014-04-16",
            33,
            18
        ]
    ]
}