← All changes
|
includes/integrations/class-google-search-console-client.php
+10
-1
2.13.0
→
2.14.1
View file →
| @@ -248,12 +248,15 @@ | ||
| 248 | 248 | * @param string $site_url Site URL to get data for |
| 249 | 249 | * @param string $start_date Start date (Y-m-d) |
| 250 | 250 | * @param string $end_date End date (Y-m-d) |
| 251 | 251 | * @param int $row_limit Maximum rows to return |
| 252 | + * @param array $dimensions Dimensions to group by | |
| 253 | + * @param array $filters Optional dimension filters (ANDed), each | |
| 254 | + * {dimension, operator, expression}. @since 2.15.0 | |
| 252 | 255 | * @return array Raw rows from GSC API |
| 253 | 256 | * @throws \Exception If API request fails |
| 254 | 257 | */ |
| 255 | - public function get_search_performance_by_dates(string $site_url, string $start_date, string $end_date, int $row_limit = 500, array $dimensions = ['query']): array { | |
| 258 | + public function get_search_performance_by_dates(string $site_url, string $start_date, string $end_date, int $row_limit = 500, array $dimensions = ['query'], array $filters = []): array { | |
| 256 | 259 | $endpoint = '/sites/' . rawurlencode($site_url) . '/searchAnalytics/query'; |
| 257 | 260 | |
| 258 | 261 | $request_body = [ |
| 259 | 262 | 'startDate' => $start_date, |
| @@ -264,8 +267,14 @@ | ||
| 264 | 267 | // data — matches what the Search Console web UI displays, so the |
| 265 | 268 | // last 2-4 days aren't missing. |
| 266 | 269 | 'dataState' => 'all', |
| 267 | 270 | ]; |
| 271 | + | |
| 272 | + // Optional dimension filters, ANDed, e.g. one page's queries: | |
| 273 | + // [['dimension' => 'page', 'operator' => 'equals', 'expression' => $url]]. | |
| 274 | + if (!empty($filters)) { | |
| 275 | + $request_body['dimensionFilterGroups'] = [['filters' => array_values($filters)]]; | |
| 276 | + } | |
| 268 | 277 | |
| 269 | 278 | $full_url = self::API_BASE_URL . $endpoint; |
| 270 | 279 | $response = $this->make_request($full_url, $request_body, 'POST'); |
| 271 | 280 | |