Skip to content

Commit

Permalink
create function for analitycs ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiofx committed Dec 7, 2010
1 parent f0de1ae commit b28ee6c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
32 changes: 3 additions & 29 deletions application/modules/admin/controllers/AjaxController.php
Expand Up @@ -93,35 +93,9 @@ public function cleancacheAction()
public function analitycsAction()
{

$id = 'Analytics';

if(!($data = $this->cache->load($id)))
{

$gapi = new Admin_Model_gapi($this->SettingsModel->get('analitycs_username'), $this->SettingsModel->get('analitycs_password'));

$gapi->requestReportData($this->SettingsModel->get('analitycs_id'),array('date'),array('visits', 'visitors'), '-date', '', date('Y-m-d', strtotime('-12 month')), date('Y-m-d'), 1, 600);
// requestReportData($report_id, $dimensions, $metrics, $sort_metric=null, $filter=null, $start_date=null, $end_date=null, $start_index=1, $max_results=30)

$cvs= "Date,visits,visitors \n";
foreach($gapi->getResults() as $result)
{
$cvs = $cvs.$result.',';
$cvs = $cvs.$result->getVisits() . ',';
$cvs = $cvs.$result->getVisitors() . "\n";
}

$this->cache->save($cvs, $id);

echo $cvs;
}
else
{
echo $this->cache->load($id);
}



$analitycsModel = new Admin_Model_Analitycs();

echo $analitycsModel->visits();

}

Expand Down
39 changes: 39 additions & 0 deletions application/modules/admin/models/Analitycs.php
Expand Up @@ -67,4 +67,43 @@ function bounce()
}

}



function visits()
{


$id = 'Analytics_visits';

if(!($data = $this->cache->load($id)))
{

$gapi = new Admin_Model_gapi($this->SettingsModel->get('analitycs_username'), $this->SettingsModel->get('analitycs_password'));

$gapi->requestReportData($this->SettingsModel->get('analitycs_id'),array('date'),array('visits', 'visitors'), '-date', '', date('Y-m-d', strtotime('-12 month')), date('Y-m-d'), 1, 600);
// requestReportData($report_id, $dimensions, $metrics, $sort_metric=null, $filter=null, $start_date=null, $end_date=null, $start_index=1, $max_results=30)

$cvs= "Date,visits,visitors \n";
foreach($gapi->getResults() as $result)
{
$cvs = $cvs.$result.',';
$cvs = $cvs.$result->getVisits() . ',';
$cvs = $cvs.$result->getVisitors() . "\n";
}

$this->cache->save($cvs, $id);

return $cvs;
}
else
{
return $this->cache->load($id);
}

}




}

0 comments on commit b28ee6c

Please sign in to comment.