← All changes
|
includes/integrations/class-google-search-analytics-client.php
+9
-2
2.9.0
→
2.14.1
View file →
| @@ -42,13 +42,16 @@ | ||
| 42 | 42 | * @param string $site_url The URL of the property in search console. |
| 43 | 43 | * @param string $start_date Start date in YYYY-MM-DD format. |
| 44 | 44 | * @param string $end_date End date in YYYY-MM-DD format. |
| 45 | 45 | * @param array $dimensions Dimensions to group by (e.g., 'query', 'page', 'country', 'device'). |
| 46 | - * @param int $row_limit Maximum number of rows to return. | |
| 46 | + * @param int $row_limit Maximum number of rows to return (the API | |
| 47 | + * accepts up to 25,000). | |
| 48 | + * @param int $start_row Zero-based offset of the first row, for | |
| 49 | + * paging past $row_limit. @since 2.15.0 | |
| 47 | 50 | * @return array Analytical data including rows and totals. |
| 48 | 51 | * @throws \Exception If the API request fails. |
| 49 | 52 | */ |
| 50 | - public function get_search_analytics_data(string $site_url, string $start_date, string $end_date, array $dimensions = [], int $row_limit = 1000): array { | |
| 53 | + public function get_search_analytics_data(string $site_url, string $start_date, string $end_date, array $dimensions = [], int $row_limit = 1000, int $start_row = 0): array { | |
| 51 | 54 | $endpoint = '/sites/' . rawurlencode($site_url) . '/searchAnalytics/query'; |
| 52 | 55 | |
| 53 | 56 | $request_body = [ |
| 54 | 57 | 'startDate' => $start_date, |
| @@ -58,8 +61,12 @@ | ||
| 58 | 61 | // Include fresh (still-processing) data so the most recent days |
| 59 | 62 | // aren't missing — matches the GSC web UI default. |
| 60 | 63 | 'dataState' => 'all', |
| 61 | 64 | ]; |
| 65 | + | |
| 66 | + if ($start_row > 0) { | |
| 67 | + $request_body['startRow'] = $start_row; | |
| 68 | + } | |
| 62 | 69 | |
| 63 | 70 | // Construct full URL. The API key is sent by make_request() in the |
| 64 | 71 | // x-goog-api-key header, not the query string (which proxies/logs capture). |
| 65 | 72 | $full_url = self::API_BASE_URL . $endpoint; |