Exemplo n.º 1
0
 public function profileAction()
 {
     $analytics = new SxCms_Analytics();
     if ($this->getRequest()->isPost()) {
         $profile = $this->_getParam('profile', '');
         if ($profile != '') {
             $analytics->setProfileid($profile)->save();
             header('Location: /admin/analytics');
             exit;
         }
     }
     require_once APPLICATION_ROOT . '/library/Gapi/gapi.php';
     require_once APPLICATION_ROOT . '/library/Gapi/gManagementApi.php';
     try {
         $ga = new gManagementApi($analytics->getLogin(), $analytics->getPass());
     } catch (exception $e) {
         $analytics->unsetAll()->save();
         header('Location: /admin/analytics');
         exit;
     }
     $accounts = $ga->requestAccountFeed();
     foreach ($accounts as $result) {
         foreach ($result as $property) {
             $profiles = $ga->requestAccountFeed($property["accountId"], '~all');
             foreach ($profiles as $result) {
                 foreach ($result as $profile) {
                     $accountProfiles[] = array("profileId" => $profile["profileId"], "profileName" => $profile["profileName"], "webPropertyId" => $profile["webPropertyId"]);
                 }
             }
             $properties[] = array("accountId" => $property["accountId"], "accountName" => $property["accountName"], "accountProfiles" => $accountProfiles);
             unset($accountProfiles);
         }
     }
     $this->view->accounts = $properties;
     $this->view->step = $analytics->getStep();
 }
<?php

require '../gapi.class.php';
require 'gManagementApi.class.php';
define('GA_EMAIL', 'myUsername');
define('GA_PASSWORD', 'mySecretPassword');
$ga = new gManagementApi(GA_EMAIL, GA_PASSWORD);
// Get all the accounts
$ga->requestAccountFeed();
// Get all web properties for all your accounts
$ga->requestAccountFeed('~all');
// Get all web properties for specfically UA-12345-2
$ga->requestAccountFeed('12345');
// To get all the profiles you have access to for web property under account 12345
$ga->requestAccountFeed('12345', '~all');
// To get the profiles for a specific web property UA-12345-2 under account 12345
$ga->requestAccountFeed('12345', 'UA-12345-2');
// To get all the goals for profile 6789 for web property UA-12345-2 under acount 12345
$ga->requestAccountFeed('12345', 'UA-12345-2', '~all');
// To get everything and the kitchen sink
$ga->requestAccountFeed('~all', '~all', '~all');
// To get all advanced segments
$ga->requestAdvancedSegmentFeed();