array( 'type' => 'array', 'items' => array( 'type' => 'string' ), 'description' => __( 'GA4 metric names, e.g. ["sessions", "totalUsers", "screenPageViews"]. At least one is required.', 'acrossai-abilities-manager' ), ), 'dimensions' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ), 'description' => __( 'GA4 dimension names, e.g. ["pagePath"] for top pages, ["sessionDefaultChannelGroup"] for traffic sources, ["date"] for a trend. Omit for totals.', 'acrossai-abilities-manager' ), ), 'start_date' => array( 'type' => 'string', 'description' => __( 'Start date, YYYY-MM-DD. Defaults with end_date to Site Kit\'s standard recent window.', 'acrossai-abilities-manager' ), ), 'end_date' => array( 'type' => 'string', 'description' => __( 'End date, YYYY-MM-DD.', 'acrossai-abilities-manager' ), ), 'url' => array( 'type' => 'string', 'description' => __( 'Restrict the report to one page URL.', 'acrossai-abilities-manager' ), ), 'order_by' => array( 'type' => 'array', 'description' => __( 'Ordering, in Google\'s own orderBys shape, e.g. [{"metric":{"metricName":"sessions"},"desc":true}].', 'acrossai-abilities-manager' ), ), 'limit' => array( 'type' => 'integer', 'default' => 20, 'minimum' => 1, 'maximum' => 1000, 'description' => __( 'Maximum rows to return.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'report' => array( 'type' => array( 'object', 'array' ) ), 'request' => array( 'type' => 'object' ), ); } protected function required_input(): array { return array( 'metrics' ); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $result = Report_Repository::analytics_report( $input ); if ( is_wp_error( $result ) ) { return $result; } $rows = is_array( $result['report'] ) && isset( $result['report']['rows'] ) && is_array( $result['report']['rows'] ) ? count( $result['report']['rows'] ) : null; $result['message'] = null === $rows ? __( 'Analytics returned a report.', 'acrossai-abilities-manager' ) : sprintf( /* translators: %d: number of rows */ __( 'Analytics returned %d rows.', 'acrossai-abilities-manager' ), $rows ); return $result; } }