Google Analytics API V4 - получение просмотров страниц для всех URL-адресов, доступных в Google Analytics одновременно - PullRequest
0 голосов
/ 22 марта 2020

Я могу получить просмотры страниц для одного указанного c URL-адреса, используя следующий код. Но я хочу получить все просмотры всех страниц моего сайта одновременно (в массив). Буду очень признателен, если вы поможете мне с этим.

function getFirstProfileId($analytics) {
// Get the user's first view (profile) ID.

// Get the list of accounts for the authorized user.
$accounts = $analytics->management_accounts->listManagementAccounts();

if (count($accounts->getItems()) > 0) {
    $items = $accounts->getItems();
    $firstAccountId = $items[0]->getId();

    // Get the list of properties for the authorized user.
    $properties = $analytics->management_webproperties
            ->listManagementWebproperties($firstAccountId);

    if (count($properties->getItems()) > 0) {
        $items = $properties->getItems();
        $firstPropertyId = $items[0]->getId();

        // Get the list of views (profiles) for the authorized user.
        $profiles = $analytics->management_profiles->listManagementProfiles($firstAccountId, $firstPropertyId);

        if (count($profiles->getItems()) > 0) {
            $items = $profiles->getItems();

            // Return the first view (profile) ID.
            return $items[0]->getId();

        } else {
            throw new Exception('No views (profiles) found for this user.');
        }
    } else {
        throw new Exception('No properties found for this user.');
    }
} else {
    throw new Exception('No accounts found for this user.');
}
}


function getResults($analytics, $profileId) {

$optParams = array(
      'filters' => 'ga:pagePath==/page1'
);

return $analytics->data_ga->get(
    'ga:' . $profileId,
    '7daysAgo',
    'today',
    'ga:pageViews',
    $optParams
);}

Я могу получить просмотры страниц для page1. Но если я хочу получить просмотры страниц для page2, page3, page4, ... et c (при условии, что у меня есть большое количество страниц, поэтому я не могу сделать это для всех из них по одной. Я пробовал, но это было очень медленно.), как я мог это сделать? Если я удалю $ opsParams, он просто даст общее количество просмотров всех этих страниц. Любая идея будет принята с благодарностью.

...