private function getTopContent($options) { if (!isset($options['limit']) or !is_numeric($options['limit'])) { throw new sfException('A limit of type integer is required'); } $arrGaReportsSettings = sfConfig::get('app_a_gareports', false); if (!isset($arrGaReportsSettings['username'])) { die('Google Analytics username is missing'); } if (!isset($arrGaReportsSettings['password'])) { die('Google Analytics password is missing '); } if (!isset($arrGaReportsSettings['profile'])) { die('Google Analytics profile is missing '); } if (!isset($arrGaReportsSettings['key'])) { die('Google Analytics API Key is missing '); } try { // create an instance of the GoogleAnalytics class using your own Google {email} and {password} // todo pull all config data from app.yml $ga = new GoogleAnalytics($arrGaReportsSettings['username'], $arrGaReportsSettings['password']); // set the Google Analytics profile you want to access - format is 'ga:123456'; $ga->setProfile($arrGaReportsSettings['profile']); $ga->setKey($arrGaReportsSettings['key']); // set the date range we want for the report - format is YYYY-MM-DD // todo: have this adjustable from the slot edit view $dateFormat = 'Y-m-d'; $startDate = date($dateFormat, strtotime('-1 month')); $endDate = date($dateFormat, time()); $ga->setDateRange($startDate, $endDate); // get the report for date and country filtered by Australia, showing pageviews and visits $report = $ga->getReport(array('dimensions' => urlencode('ga:pagetitle,ga:pagePath'), 'metrics' => urlencode('ga:pageviews'), 'sort' => '-ga:pageviews', 'max-results' => $options['limit']), $returnJson = TRUE); } catch (Exception $e) { $report = 'Error: ' . $e->getMessage(); } return $report; }