← All changes
|
includes/integrations/class-google-search-analytics-client.php
+12
-3
1.27.0
→
2.14.1
View file →
| @@ -42,14 +42,17 @@ | ||
| 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 { | |
| 51 | - $endpoint = '/sites/' . urlencode($site_url) . '/searchAnalytics/query'; | |
| 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 { | |
| 54 | + $endpoint = '/sites/' . rawurlencode($site_url) . '/searchAnalytics/query'; | |
| 52 | 55 | |
| 53 | 56 | $request_body = [ |
| 54 | 57 | 'startDate' => $start_date, |
| 55 | 58 | 'endDate' => $end_date, |
| @@ -59,8 +62,12 @@ | ||
| 59 | 62 | // aren't missing — matches the GSC web UI default. |
| 60 | 63 | 'dataState' => 'all', |
| 61 | 64 | ]; |
| 62 | 65 | |
| 66 | + if ($start_row > 0) { | |
| 67 | + $request_body['startRow'] = $start_row; | |
| 68 | + } | |
| 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; |
| 66 | 73 | |
| @@ -76,8 +83,10 @@ | ||
| 76 | 83 | /** |
| 77 | 84 | * Test the connection to the API |
| 78 | 85 | * |
| 79 | 86 | * @return array Connection test result |
| 87 | + * | |
| 88 | + * @throws \Exception On failure. | |
| 80 | 89 | */ |
| 81 | 90 | public function test_connection(): array { |
| 82 | 91 | try { |
| 83 | 92 | // We can't easily test without a site URL, but we can check if credentials are present |