<?php

require "rtapi.class.php";
$ga_profile_id = "xxxxxx";
//your google analytics account ID
$metrics = array("activeUsers");
$dimensions = array("userType");
//"userType","medium","city"
$rt = new rtapi("*****@*****.**", "oauthkeyfile.p12");
$rt->requestReportData($ga_profile_id, $dimensions, $metrics);
$result = $rt->getResults();
/*
echo '<pre>';
print_r($result[0]);
echo '</pre>';
*/
if ($result == NULl) {
    $useronline = 0;
    $pluriel = "";
} else {
    $useronline = $result[0]->getactiveUsers();
    if ($useronline > 1) {
        $pluriel = "s";
    }
}
echo $useronline . " Visiteur" . $pluriel . " en ligne";
 /**
  * Call method to find a matching metric or dimension to return
  *
  * @param String $name name of function called
  * @param Array $parameters
  * @return String
  * @throws Exception if not a valid metric or dimensions, or not a 'get' function
  */
 public function __call($name, $parameters)
 {
     if (!preg_match('/^get/', $name)) {
         throw new Exception('No such function "' . $name . '"');
     }
     $name = preg_replace('/^get/', '', $name);
     $metric_key = rtapi::ArrayKeyExists($name, $this->metrics);
     if ($metric_key) {
         return $this->metrics[$metric_key];
     }
     $dimension_key = rtapi::ArrayKeyExists($name, $this->dimensions);
     if ($dimension_key) {
         return $this->dimensions[$dimension_key];
     }
     throw new Exception('No valid metric or dimesion called "' . $name . '"');
 }