Good day,
Is there a way to get the next 10,000 data from google analytics API? I would want to get the next set of data after getting the first 10,000. Is there a way to accomplish that? I am using google analytics api php client libraries.
Here is my code:
<?php
$analytics = initializeAnalytics();
$response = getReport($analytics);
printResults($response);
function initializeAnalytics()
{
$KEY_FILE_LOCATION = __DIR__ . 'MyFileDirectory';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client-
>setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_AnalyticsReporting($client);
return $analytics;
}
function getReport($analytics) {
// Replace with your view ID, for example XXXX.
$VIEW_ID = "MyViewId";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("2017-04-01");
$dateRange->setEndDate("2017-06-19");
// Create the Metrics object.
$totalEvents = new Google_Service_AnalyticsReporting_Metric();
$totalEvents->setExpression("ga:totalEvents");
$totalEvents->setAlias("totalEvents");
//Create the Dimensions object.
$clientId = new Google_Service_AnalyticsReporting_Dimension();
$clientId->setName("ga:dimension4");
$sessionId = new Google_Service_AnalyticsReporting_Dimension();
$sessionId->setName("ga:dimension5");
$eventLabel = new Google_Service_AnalyticsReporting_Dimension();
$eventLabel->setName("ga:eventLabel");
$timestamp = new Google_Service_AnalyticsReporting_Dimension();
$timestamp->setName("ga:dimension3");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
//set number of rows
$request->setPageSize(10000);
$request->setDateRanges($dateRange);
$request->setMetrics(array($totalEvents));
$request->setDimensions(array($clientId,$sessionId,$eventLabel,
$timestamp));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
}
?>