Skip to content
Go to file
Cannot retrieve contributors at this time
62 lines (52 sloc) 1.68 KB
// MUST be using composer
require_once '/home/csengineer13/';
$client = new Google_Client();
$client->setApplicationName("API Project"); // Name of proj in GoogleDeveloperConsole
// Generated in GoogleDeveloperConsole --> Credentials --> Service Accounts
$client->setAuthConfig('/home/csengineer13/secure-creds/API Project-c0a14bc34a03.json');
// Grab token if it's set
if (isset($_SESSION['service_token'])) {
// Refresh if expired
if ($client->isAccessTokenExpired()) {
// Pin to Session
$_SESSION['service_token'] = $client->getAccessToken();
$service = new Google_Service_Analytics($client);
// Adding Dimensions
$params = array('dimensions' => 'ga:userType');
// requesting the data
$data = $service->data_ga->get("ga:110849216", "2015-10-01", "2015-11-08", "ga:users,ga:sessions", $params );
<title>PHP Only: Data Query</title>
<h1>Results for: 2015-10 to 2015-11-08</h1>
<table border="1">
//Printing column headers
foreach($data->getColumnHeaders() as $header){
print "<td><b>".$header['name']."</b></td>";
//printing each row.
foreach ($data->getRows() as $row) {
print "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
<td colspan="2">Rows Returned <?php print $data->getTotalResults();?> </td>
You can’t perform that action at this time.