public function admin_index() { $this->set('title', __('Dashboard')); //$this->set('description', __('Manage Quiz')); $practiceTests = $this->PracticeTest->find('all', array('order' => array('PracticeTest.created' => 'DESC'), 'limit' => 20)); $this->set('practiceTests', $practiceTests); $FavouritePracticeTests = $this->PracticeTest->find('all', array('order' => array('PracticeTest.avg' => 'DESC'), 'limit' => 10)); $this->set('FavouritePracticeTests', $FavouritePracticeTests); $users = $this->User->find('all', array('order' => array('User.created' => 'DESC'), 'limit' => 10)); $this->set('users', $users); //google analytics if (Configure::read('GA.email') != '' && Configure::read('GA.password') != '') { try { // construct the class $oAnalytics = new analytics(Configure::read('GA.email'), Configure::read('GA.password')); // set it up to use caching $oAnalytics->useCache(); //$oAnalytics->setProfileByName(Configure::read('GA.domain')); $oAnalytics->setProfileById(Configure::read('GA.profile_id')); // set the date range //$oAnalytics->setMonth(date('n'), date('Y')); $oAnalytics->setDateRange(date('Y-m-d', strtotime('-1 week')), date('Y-m-d')); //echo '<pre>'; // print out visitors for given period //print_r($oAnalytics->getVisitors()); // print out pageviews for given period //print_r($oAnalytics->getPageviews()); // use dimensions and metrics for output // see: http://code.google.com/intl/nl/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html // print_r($oAnalytics->getData(array( 'dimensions' => 'ga:keyword', // 'metrics' => 'ga:visits', // 'sort' => 'ga:keyword'))); //print_r($oAnalytics->getData(array('dimensions' => 'ga:visitorType','metrics' => 'ga:newVisits'))); $visits = $oAnalytics->getVisitors(); $views = $oAnalytics->getPageviews(); /* build tables */ if (count($visits)) { $visits = $this->array_filter_recursive($visits); $views = $this->array_filter_recursive($views); foreach ($visits as $day => $visit) { $flot_datas_visits[] = '[' . $day . ',' . $visit . ']'; $flot_datas_views[] = '[' . $day . ',' . $views[$day] . ']'; } $flot_data_visits = '[' . implode(',', $flot_datas_visits) . ']'; $flot_data_views = '[' . implode(',', $flot_datas_views) . ']'; } $this->set(compact('flot_data_visits', 'flot_data_views')); } catch (Exception $e) { //echo 'Caught exception: ' . $e->getMessage(); } } }
/* including the charts class for displaying user activity for the past week. */ include "../" . MODS_DIRECTORY . "/charts/FusionCharts_Gen.php"; include "../" . USER_DIRECTORY . "/header.php"; $js = "<script language=\"javascript\" src=\"{$website}/" . JS_DIRECTORY . "/FusionCharts.js\"></script>"; subheader(_("Statistics"), null, $js); if ($sesslife == true) { if ($is_admin == 1) { echo "<div class=\"page-header\"><h1>" . _("Statistics") . "</h1></div>"; echo "<h6>" . _("Options") . " : <a href=\"{$website}/" . ADMIN_DIRECTORY . "/settings#/analytics\">" . _("Analytics Settings") . "</a></h6><br/>"; echo "<ul class=\"breadcrumb\">\n\t\t<li><a href=\"{$website}/" . ADMIN_DIRECTORY . "/settings\">" . _("Home") . "</a> <span class=\"divider\">/</span></li>\n\t\t<li class=\"active\">" . _("Statistics") . "</li>\n\t\t</ul>"; if (!empty($_setting['google_id']) && !empty($_setting['google_password']) && !empty($_setting['site_id'])) { echo "<div class=\"alert\">" . _("Google ID") . " : <strong>{$_setting['google_id']}</strong> " . _("Site ID") . " : <strong>{$_setting['site_id']}</strong></div>"; $analytics = new analytics($_setting['google_id'], $_setting['google_password']); $analytics->setProfileById("ga:" . $_setting['site_id']); $analytics->setMonth(date("n"), date("Y")); $month = date("M"); $visitors = $analytics->getVisitors(); $total = count($visitors); $basic = 0; $count = "01"; while ($count < $total + 1) { $arrData[$basic][0] = $count; $arrData[$basic][1] = $visitors[$count]; $count++; $basic++; if ($count < 10) { $count = "0" . $count; } }
header('Location: ' . htmlspecialchars($_SERVER['PHP_SELF'])); exit; } if (isset($_SESSION['username'], $_SESSION['password'])){ // construct the class $oAnalytics = new analytics($_SESSION['username'], $_SESSION['password']); // get an array with profiles (profileId => profileName) $aProfiles = $oAnalytics->getProfileList(); $aProfileKeys = array_keys($aProfiles); // set the profile tot the first account $oAnalytics->setProfileById($aProfileKeys[0]); $iSelectedMonth = date('n'); } if (isset($_POST['profileId'])){ // change profileId $oAnalytics->setProfileById($_POST['profileId']); } if (isset($_POST['month'])){ // change month $iSelectedMonth = $_POST['month']; } // set the month $oAnalytics->setMonth($iSelectedMonth, date('Y')); // alternativly set a date range:
public function display_results($email, $password, $profile_id) { require_once 'lib/analytics.class.php'; // session_start for caching session_start(); try { // construct the class $oAnalytics = new analytics($email, $password); // set it up to use caching $oAnalytics->useCache(); //$oAnalytics->setProfileByName('[Google analytics accountname]'); $oAnalytics->setProfileById('ga:'.$profile_id); // set the date range $last_month = date("Y-m-d", strtotime('today - 30 days')); $today = date("Y-m-d", strtotime('today')); //$oAnalytics->setMonth(date('n'), date('Y')); $oAnalytics->setDateRange($last_month, $today); $wrapper = new XMLElement('div'); $graph = extension_dashboard_analytics::buildChart($oAnalytics); $wrapper->appendChild($graph); $info = new XMLElement('div'); $info->setAttribute('class', 'info'); $info_header = new XMLElement('h4', 'Quick Information'); $dl_results = new XMLElement('dl'); //Total Pageviews $dt_pageviews = new XMLElement('dt', 'Pageviews'); $dd_pageviews = new XMLElement('dd', array_sum($oAnalytics->getPageviews())); $dl_results->appendChild($dt_pageviews); $dl_results->appendChild($dd_pageviews); //Total Visits $dt_visits = new XMLElement('dt', 'Visits'); $dd_visits = new XMLElement('dd', array_sum($oAnalytics->getVisitors())); $dl_results->appendChild($dt_visits); $dl_results->appendChild($dd_visits); //Pages/Visit $pages_visits = $oAnalytics->getData( array('metrics'=> urlencode('ga:pageviewsPerVisit')) ); $dt_pages_visits = new XMLElement('dt', 'Pages per Visit'); $dd_pages_visits = new XMLElement('dd', round(array_sum($pages_visits),2)); $dl_results->appendChild($dt_pages_visits); $dl_results->appendChild($dd_pages_visits); $bounce_rate = $oAnalytics->getData( array('metrics'=> urlencode('ga:visitBounceRate')) ); $dt_bounce_rate = new XMLElement('dt', 'Bounce Rate'); $dd_bounce_rate = new XMLElement('dd', round(array_sum($bounce_rate),2).'%'); $dl_results->appendChild($dt_bounce_rate ); $dl_results->appendChild($dd_bounce_rate); //% New Visits $new_visits = $oAnalytics->getData( array('metrics'=> urlencode('ga:percentNewVisits')) ); $dt_new_visits = new XMLElement('dt', '% New Visits'); $dd_new_visits = new XMLElement('dd', round(array_sum($new_visits),2).'%'); $dl_results->appendChild($dt_new_visits); $dl_results->appendChild($dd_new_visits); //Avg Time on Site $average_time = $oAnalytics->getData( array('metrics'=> urlencode('ga:avgTimeOnSite')) ); $dt_average_time = new XMLElement('dt', 'Avg. Time on Site'); $dd_average_time = new XMLElement('dd', extension_dashboard_analytics::sec2hms(round(array_sum($average_time),0))); $dl_results->appendChild($dt_average_time); $dl_results->appendChild($dd_average_time); $search_terms = new XMLElement('div'); $search_terms->setAttribute('class', 'terms'); //Search Terms $terms_head = new XMLElement('h4', 'Top Keywords'); $terms = new XMLElement('ol'); $keywords = array_keys($oAnalytics->getSearchWords()); $count = 0; foreach($keywords as $keyword) { $item = new XMLElement('li', $keyword); $terms->appendChild($item); $count++; if ($count == 10) break; } $info->appendChild($info_header); $info->appendChild($dl_results); $search_terms->appendChild($terms_head); $search_terms->appendChild($terms); $wrapper->appendChild($info); $wrapper->appendChild($search_terms); return $wrapper; } catch (Exception $e) { $info = new XMLElement('div'); $info->setAttribute('class', 'info'); $info_header = new XMLElement('h4', 'No data found. Check your account details.'); $info->appendChild($info_header); $info_header->appendChild(new XMLElement('p', '<code>'.(string)$e->getMessage().'</code>')); return $info; } }
function scrapeGoogle($q) { $q = urlencode($q); $url = "http://www.google.com/uds/GwebSearch?callback=google.search.WebSearch.RawCompletion&context=0&lstkp=0&rsz=large&hl=en&source=gsc&gss=.com&sig=c1cdabe026cbcfa0e7dc257594d6a01c&q={$q}%20site%3Awikihow.com&gl=www.google.com&qid=124c49541548cd45a&key=ABQIAAAAYdkMNf23adqRw4vVq1itihTad9mjNgCjlcUxzpdXoz7fpK-S6xTT265HnEaWJA-rzhdFvhMJanUKMA&v=1.0"; $contents = file_get_contents($url); #echo $q . "\n"; $result = preg_match('@unescapedUrl":"([^"]*)"@u', $contents, $matches); return $matches[1]; } try { // construct the class $oAnalytics = new analytics('tderouin', 'rem700sps'); // set it up to use caching $oAnalytics->useCache(); #$oAnalytics->setProfileByName('[Google analytics accountname]'); $oAnalytics->setProfileById('ga:16643416'); // set the date range $oAnalytics->setMonth(date('n'), date('Y')); // or $oAnalytics->setDateRange('YYYY-MM-DD', 'YYYY-MM-DD'); // print out visitors for given period #print_r($oAnalytics->getVisitors()); // print out pageviews for given period #print_r($oAnalytics->getPageviews()); // use dimensions and metrics for output // see: http://code.google.com/intl/nl/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html $results = $oAnalytics->getData(array('dimensions' => 'ga:keyword', 'metrics' => 'ga:visits', 'sort' => '-ga:visits')); $skip = array("(other)", "(not set)", "wikihow", "wiki how"); array_shift($results); foreach ($results as $r => $c) { $r = trim(preg_replace("@^how to@im", "", $r)); if (in_array($r, $skip)) {
if ($username == "" || $password == "" || $profileId == "") { print array2json(array("status" => 403, "message" => "Please edit the config.php!")); exit; } try { // construct the class $oAnalytics = new analytics($username, $password); // set it up to use caching $oAnalytics->useCache(); // get an array with profiles (profileId => profileName) $aProfiles = $oAnalytics->getProfileList(); $aProfileKeys = array_keys($aProfiles); // set the profile tot the first account if (in_array($profileId, $aProfileKeys)) { // set profile by id $oAnalytics->setProfileById($profileId); } else { $message = "The profile Id in a config.php is not correct!"; $message .= "<br />Available in account: <ul>"; foreach ($aProfiles as $id => $name) { $message .= "<li><b>{$id}</b> ({$name})</li>"; } $message .= "</ul>"; print array2json(array("status" => 403, "message" => $message)); exit; } $yesterday = date("Y-m-d", time() - 1 * 24 * 60 * 60); // set the date range between yesterday and before 1 mmonth $oAnalytics->setDateRange(date("Y-m-d", strtotime("-1 month", time() - 1 * 24 * 60 * 60)), $yesterday); // Select metrics foreach ($_POST['data'] as $items) {