Skip to content

Commit

Permalink
Stats: Add Devices Stats endpoint support (#37098)
Browse files Browse the repository at this point in the history
* Proxy Devices Stats API endpoint

* changelog

* fix up project versions

---------

Co-authored-by: Jasper Kang <[email protected]>
  • Loading branch information
dognose24 and kangzj authored Apr 29, 2024
1 parent 1c7bf2e commit da79b1e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Proxy Devices Stats API endpoint.
2 changes: 1 addition & 1 deletion projects/packages/stats-admin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"autotagger": true,
"mirror-repo": "Automattic/jetpack-stats-admin",
"branch-alias": {
"dev-trunk": "0.18.x-dev"
"dev-trunk": "0.19.x-dev"
},
"textdomain": "jetpack-stats-admin",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/stats-admin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-stats-admin",
"version": "0.18.3",
"version": "0.19.0-alpha",
"description": "Stats Dashboard",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/stats-admin/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/stats-admin/src/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Main {
/**
* Stats version.
*/
const VERSION = '0.18.3';
const VERSION = '0.19.0-alpha';

/**
* Singleton Main instance.
Expand Down
33 changes: 33 additions & 0 deletions projects/packages/stats-admin/src/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ public function register_rest_routes() {
)
);

// Get Devices stats time series.
register_rest_route(
static::$namespace,
// /stats/devices/screensize
sprintf( '/sites/%d/stats/devices/(?P<device_property>[\w]+)', Jetpack_Options::get_option( 'id' ) ),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_devices_stats_time_series' ),
'permission_callback' => array( $this, 'can_user_view_general_stats_callback' ),
)
);

// Rerun commercial classificiation.
register_rest_route(
static::$namespace,
Expand Down Expand Up @@ -871,6 +883,27 @@ public function get_utm_stats_time_series( $req ) {
);
}

/**
* Get Devices stats time series.
*
* @param WP_REST_Request $req The request object.
* @return array
*/
public function get_devices_stats_time_series( $req ) {
return WPCOM_Client::request_as_blog_cached(
sprintf(
'/sites/%d/stats/devices/%s?%s',
Jetpack_Options::get_option( 'id' ),
$req->get_param( 'device_property' ),
$this->filter_and_build_query_string(
$req->get_params()
)
),
'v1.1',
array( 'timeout' => 10 )
);
}

/**
* Dismiss or delay stats notices.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/jetpack/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
]
},
"config": {
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_1_18"
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_1_19_alpha"
}
}
4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Plugin Name: WordPress.com Features
* Description: Test plugin for the jetpack-mu-wpcom package
* Version: 2.1.18
* Version: 2.1.19-alpha
* Author: Automattic
* License: GPLv2 or later
* Text Domain: jetpack-mu-wpcom-plugin
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom-plugin",
"version": "2.1.18",
"version": "2.1.19-alpha",
"description": "Test plugin for the jetpack-mu-wpcom package",
"homepage": "https://jetpack.com",
"bugs": {
Expand Down

0 comments on commit da79b1e

Please sign in to comment.