2.7K members online now
2.7K 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

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] =>
    [itemsPerPage] => 1000
    [kind] => analytics#gaData
    [nextLink] =>
    [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>';
    } 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

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,
Web analyst @