}> * @throws ApiError On failure. */ public function account_summaries(): array { $result = array(); $page_token = null; for ( $page = 0; $page < self::MAX_PAGES; $page++ ) { $response = $this->call( 'GET', $this->paged_url( self::BASE . '/accountSummaries?pageSize=200', $page_token ) ); foreach ( (array) ( $response['accountSummaries'] ?? array() ) as $account ) { if ( ! is_array( $account ) ) { continue; } $result[] = array( 'account' => (string) ( $account['account'] ?? '' ), 'account_name' => (string) ( $account['displayName'] ?? '' ), 'properties' => $this->normalize_properties( (array) ( $account['propertySummaries'] ?? array() ) ), ); } $page_token = isset( $response['nextPageToken'] ) && is_string( $response['nextPageToken'] ) && '' !== $response['nextPageToken'] ? $response['nextPageToken'] : null; if ( null === $page_token ) { break; } } return $result; } /** * The web data streams of a property (app streams are excluded). * * @param string $property_id A property resource name, e.g. 'properties/123'. * @return array * @throws ApiError On failure. */ public function web_streams( string $property_id ): array { $this->assert_property_id( $property_id ); $result = array(); $page_token = null; for ( $page = 0; $page < self::MAX_PAGES; $page++ ) { $response = $this->call( 'GET', $this->paged_url( self::BASE . '/' . $property_id . '/dataStreams', $page_token ) ); foreach ( (array) ( $response['dataStreams'] ?? array() ) as $stream ) { if ( ! is_array( $stream ) || 'WEB_DATA_STREAM' !== ( $stream['type'] ?? '' ) ) { continue; } $web_data = is_array( $stream['webStreamData'] ?? null ) ? $stream['webStreamData'] : array(); $result[] = array( 'stream_id' => (string) ( $stream['name'] ?? '' ), 'name' => (string) ( $stream['displayName'] ?? '' ), 'measurement_id' => (string) ( $web_data['measurementId'] ?? '' ), 'default_uri' => (string) ( $web_data['defaultUri'] ?? '' ), ); } $page_token = isset( $response['nextPageToken'] ) && is_string( $response['nextPageToken'] ) && '' !== $response['nextPageToken'] ? $response['nextPageToken'] : null; if ( null === $page_token ) { break; } } return $result; } /** * Normalizes an accountSummaries entry's propertySummaries. * * @param array $properties Raw propertySummaries entries. * @return array */ private function normalize_properties( array $properties ): array { $result = array(); foreach ( $properties as $property ) { if ( ! is_array( $property ) ) { continue; } $result[] = array( 'property_id' => (string) ( $property['property'] ?? '' ), 'name' => (string) ( $property['displayName'] ?? '' ), ); } return $result; } /** * Appends a pageToken query param to a URL when present. * * @param string $url Base URL, with its own query string already appended. * @param string|null $page_token Page token, or null for the first page. */ private function paged_url( string $url, ?string $page_token ): string { if ( null === $page_token ) { return $url; } return $url . '&pageToken=' . rawurlencode( $page_token ); } }