setProperty('properties/' . $propertyId) ->setDimensions([new Dimension(['name' => 'country'])]) ->setMetrics([new Metric(['name' => 'activeUsers'])]); $response = $client->runRealtimeReport($request); printRunRealtimeReportResponse($response); } /** * Print results of a runRealtimeReport call. * @param RunRealtimeReportResponse $response */ function printRunRealtimeReportResponse(RunRealtimeReportResponse $response) { // [START analyticsdata_print_run_realtime_report_response_header] printf('%s rows received%s', $response->getRowCount(), PHP_EOL); foreach ($response->getDimensionHeaders() as $dimensionHeader) { printf('Dimension header name: %s%s', $dimensionHeader->getName(), PHP_EOL); } foreach ($response->getMetricHeaders() as $metricHeader) { printf( 'Metric header name: %s (%s)%s', $metricHeader->getName(), MetricType::name($metricHeader->getType()), PHP_EOL ); } // [END analyticsdata_print_run_realtime_report_response_header] // [START analyticsdata_print_run_realtime_report_response_rows] print 'Report result: ' . PHP_EOL; foreach ($response->getRows() as $row) { printf( '%s %s' . PHP_EOL, $row->getDimensionValues()[0]->getValue(), $row->getMetricValues()[0]->getValue() ); } // [END analyticsdata_print_run_realtime_report_response_rows] } // [END analyticsdata_run_realtime_report] // The following 2 lines are only needed to run the samples require_once __DIR__ . '/../testing/sample_helpers.php'; return \Google\Analytics\Data\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);