/**
  *	fetchData is just pulling in raw data like it is coming form the API and is supposed to be a data provider
  *	for functions that return certain formats like GoogleDataStore::fetchPerformance()
  *	
  *	@param Query assoc Array containing all necessary query parameters that are not already set, @see GoogleDataStore::$query
  *	@return Query Array containing raw data retrieved from the analytics_api.php
  **/
 public function fetchData($query)
 {
     require_once '../googleanalytics/thirdparty/analytics_api.php';
     // prep query params
     $query = array_merge($this->query, $query);
     // get cache object
     $q = substr(GoogleAnalyzer::get_sapphire_version(), 0, 3) == '2.3' ? '`' : '"';
     $hash = hash('md5', serialize(array_merge($this->setup, $query)));
     $cache = DataObject::get_one('GoogleCachedQuery', "{$q}GoogleCachedQuery{$q}.{$q}Hash{$q} = '{$hash}'");
     if (!$cache) {
         $cache = new GoogleCachedQuery(array('Hash' => $hash));
     }
     // poll fresh data if cached query is empty or outdated
     if (date('Y-m-d', strtotime($cache->LastEdited)) != date('Y-m-d')) {
         $api = new analytics_api();
         if ($api->login($this->setup['email'], $this->setup['password'])) {
             // $xml = $api->call($this->setup['url']);
             $data = $api->data('ga:' . $this->setup['ids'], $query['dimensions'], $query['metrics'], $query['sort'], $query['start-date'], $query['end-date'], $query['max-results'], $query['start-index'], $query['filters']);
             $cache->Data = serialize($data);
             $cache->write();
         } else {
             trigger_error('ERROR: failed to connect remote server.');
         }
     } else {
         $data = unserialize($cache->Data);
     }
     return $data;
 }
Example #2
0
    public function indexAction($params)
    {
        
        
        // enter your login, password and id into the variables below to try it out

        $login = GAQ_USERNAME;
        $password = GAQ_PASSWORD;

        // NOTE: the id is in the form ga:12345 and not just 12345
        // if you do e.g. 12345 then no data will be returned
        // read http://www.electrictoolbox.com/get-id-for-google-analytics-api/ for info about how to get this id from the GA web interface
        // or load the accounts (see below) and get it from there
        // if you don't specify an id here, then you'll get the "Badly formatted request to the Google Analytics API..." error message
        $id = GAQ_PROFILE_ID;

        $api = new analytics_api();
        if($api->login($login, $password)) {

                parent::set('visitors', $api->data($id, '', 'ga:bounces,ga:newVisits,ga:visits,ga:pageviews,ga:uniquePageviews'));
                parent::set('visitorsToday', $api->get_summary($id, 'today'));
        }
    }
Example #3
0
require_once 'analytics_api.php';
$gaquery = yasDB_select("SELECT `galogin`, `gapassword`, `gaurl` FROM `settings` WHERE id=1");
$gaLogin = $gaquery->fetch_array(MYSQLI_ASSOC);
?>
<div id="center-column">
<div class="top-bar">
<h1>Cpanel - Google Analytics</h1>
<div class="breadcrumbs"><a href="index.php?act=gainfo" title="Google Analytics Info">Google Analytics Login Info</a></div>
</div><br />
<div class="select-bar">
<label>
<h3>Google Analytics Data</h3>
</label>
</div>
<?php 
$api = new analytics_api();
if ($api->login($gaLogin['galogin'], $gaLogin['gapassword'])) {
    $api->load_accounts();
    $tableId = $api->getAccountsTableIdFromName($gaLogin['gaurl']);
    $data = $api->data($tableId, 'ga:date', 'ga:visits', 'ga:date', date('Y-m-d', strtotime('1 month ago')), date('Y-m-d'), 33);
    $amounts = array();
    $amounts2 = array();
    $amounts3 = array();
    foreach ($data as $i => $value) {
        $amounts[substr($i, 4, 2) . '/' . substr($i, 6, 2)] = $value['ga:visits'];
    }
    $_SESSION['amounts'] = serialize($amounts);
    $_SESSION['url'] = $gaLogin['gaurl'];
    unset($amounts);
    // output image
    ?>
<?php

//
require_once 'analytics_api.php';
// enter your login, password and id into the variables below
$login = '';
$password = '';
// NOTE: the id is in the form ga:12345 and not just 12345
// if you do e.g. 12345 then no data will be returned
// or load the accounts (see below) and get it from there
// if you don't specify an id here, then you'll get the "Badly formatted request to the Google Analytics API..." error message
$id = '';
$api = new analytics_api();
if ($api->login($login, $password)) {
    echo "login success\n";
    if (false) {
        // ->load_accounts() loads the accounts in your profile you have access to into ->accounts
        // read more about this at the following urls:
        // http://www.electrictoolbox.com/get-google-analytics-profile-id-accounts-list/
        // http://www.electrictoolbox.com/php-google-analytics-load-accounts-list/
        // note: you don't actually need to load the accounts to use the analytics class
        $api->load_accounts();
        print_r($api->accounts);
        /*
        example output:
        Array
        (
            [www.electrictoolbox.com] => Array
                (
                    [tableId] => ga:7426158
                    [accountId] => 144582