<?php require_once __DIR__ . '/bootstrap.php'; use Gapi\Gapi; $ga = new Gapi(ga_email, ga_password); /** * Note: OR || operators are calculated first, before AND &&. * There are no brackets () for precedence and no quotes are * required around parameters. * * Do not use brackets () for precedence, these are only valid for * use in regular expressions operators! * * The below filter represented in normal PHP logic would be: * country == 'United States' && ( browser == 'Firefox || browser == 'Chrome') */ $filter = 'country == United States && browser == Firefox || browser == Chrome'; $ga->requestReportData(ga_profile_id, array('browser', 'browserVersion'), array('pageviews', 'visits'), '-visits', $filter); ?> <table> <tr> <th>Browser & Browser Version</th> <th>Pageviews</th> <th>Visits</th> </tr> <?php foreach ($ga->getResults() as $result) { ?> <tr> <td><?php echo $result;
/** * 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 = Gapi::ArrayKeyExists($name, $this->metrics); if ($metric_key) { return $this->metrics[$metric_key]; } $dimension_key = Gapi::ArrayKeyExists($name, $this->dimensions); if ($dimension_key) { return $this->dimensions[$dimension_key]; } throw new Exception('No valid metric or dimesion called "' . $name . '"'); }
<?php require_once __DIR__ . '/bootstrap.php'; use Gapi\Gapi; $ga = new Gapi(ga_email, ga_password); $ga->requestAccountData(); foreach ($ga->getResults() as $result) { echo "<br />"; echo $result . ' (' . $result->getProfileId() . ") \r\n"; } echo "\r\n";
<?php require_once __DIR__ . '/bootstrap.php'; use Gapi\Gapi; $ga = new Gapi(ga_email, ga_password, isset($_SESSION['ga_auth_token']) ? $_SESSION['ga_auth_token'] : null); $_SESSION['ga_auth_token'] = $ga->getAuthToken(); echo 'Token: ' . $_SESSION['ga_auth_token'];