AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
3.8K members online now
3.8K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

How to use pagination to retrieve next result set?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

How to get "next page" data by using Google Analytics PHP API?

I have this code. Everything works fine. I'm getting 1000 results (rows), but i need to get other rows if total result is more then 1000. 

[columnHeadersType:protected] => Google_Service_Analytics_GaDataColumnHeaders
    [columnHeadersDataType:protected] => array
    [containsSampledData] => 
    [dataTableType:protected] => Google_Service_Analytics_GaDataDataTable
    [dataTableDataType:protected] => 
    [id] => https://www.googleapis.com/analytics/v3/data/ga?ids=ga:479...&start-date=yesterday&end-date=yesterday
    [itemsPerPage] => 1000
    [kind] => analytics#gaData
    [nextLink] => https://www.googleapis.com/analytics/v3/data/ga?...&start-index=1001&max-results=1000
    [previousLink] => 
    [profileInfoType:protected] => Google_Service_Analytics_GaDataProfileInfo
    [profileInfoDataType:protected] => 
    [queryType:protected] => Google_Service_Analytics_GaDataQuery
    [queryDataType:protected] => 
    [rows] => Array

 

function getResults(&$analytics, $profileId) {

    $params = array('dimensions' => 'ga:pagePath,ga:deviceCategory,ga:city,ga:operatingSystem,ga:screenResolution,ga:sourceMedium,ga:keyword');


    $data = $analytics->data_ga->get('ga:' . $profileId, 'yesterday', 'yesterday', 'ga:sessions,ga:hits,ga:sessionDuration', $params);

    return $data;
}

function printResults(&$results) {
    // Parses the response from the Core Reporting API and prints
    // the profile name and total sessions.
    if (count($results->getRows()) > 0) {

        // Get the profile name.
        $profileName = $results->getProfileInfo()->getProfileName();

        // Get the entry for the first entry in the first row.
        $rows = $results->getRows();

        echo '<pre>';
        print_r($rows);
    } else {
        print "No results found.\n";
    }
}

 

 

1 Expert replyverified_user

Re: How to use pagination to retrieve next result set?

Top Contributor
# 2
Top Contributor
Hi,

not sure if this is what you are looking for but you can override the parameter max-results up to 10 000 rows or you can in addition experiment with start index if you want to get results from multiple queries (+10 000).

Kind regards,
Zorin
Web analyst @ escapestudio.net