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(); } } }
function ajax_load() { $ga = new analytics(); if ($_GET) { $now = Date2DB($_GET['date']); } else { $now = date("Y-m-d"); } $lastmonth = date('Y-m-d', strtotime('-29 days', mysql_to_unix($now))); //Last 10 days visitors (for graph) //$data['visits']=$this->ga->getVisits($lastmonth,$now,30); $visits = $ga->getResultDate('visits', $lastmonth, $now); foreach ($visits as $key => $v) { $data['visits'][$key]['ga:date'] = $v['0']; $data['visits'][$key]['ga:visits'] = $v['1']; } //Summery: visitors, unique visit, pageview, time on site, new visits, bounce rates //$data['summery']=$this->ga->getSummery($lastmonth,$now); $data['summery']['ga:visits'] = $ga->getResult('visits', $lastmonth, $now); $data['summery']['ga:visitors'] = $ga->getResult('visitors', $lastmonth, $now); $data['summery']['ga:pageviews'] = $ga->getResult('pageviews', $lastmonth, $now); $data['summery']['ga:timeOnSite'] = $ga->getResult('timeOnSite', $lastmonth, $now); $data['summery']['ga:newVisits'] = $ga->getResult('newVisits', $lastmonth, $now); $data['summery']['ga:bounces'] = $ga->getResult('bounces', $lastmonth, $now); $data['summery']['ga:entrances'] = $ga->getResult('entrances', $lastmonth, $now); //All time summery: visitors, page views //$data['allTimeSummery']=$this->ga->getAllTimeSummery(); $data['allTimeSummery']['ga:visits'] = $ga->getResult('visits', '2005-01-01', $now); $data['allTimeSummery']['ga:pageviews'] = $ga->getResult('pageviews', '2005-01-01', $now); //Top 10 visitor countries //$data['topCountries']=$this->ga->getTopCountry($lastmonth,$now,10); $topCountries = $ga->getResultDate('visits', $lastmonth, $now, 'country', '10', '-ga:visits'); foreach ($topCountries as $key => $v) { $data['topCountries'][$key]['ga:country'] = $v['0']; $data['topCountries'][$key]['ga:visits'] = $v['1']; } //Top 10 search engine keywords //$data['topKeywords'] = $this->ga->getTopKeyword($lastmonth,$now,10); $topKeywords = $ga->getResultDate('visits', $lastmonth, $now, 'keyword', '10', '-ga:visits'); foreach ($topKeywords as $key => $v) { $data['topKeywords'][$key]['ga:keyword'] = $v['0']; $data['topKeywords'][$key]['ga:visits'] = $v['1']; } //Top 10 referrer websites //$data['topReferrer']=$this->ga->getTopReferrer($lastmonth,$now,10); $topReferrer = $ga->getResultDate('visits', $lastmonth, $now, 'source', '10', '-ga:visits'); foreach ($topReferrer as $key => $v) { $data['topReferrer'][$key]['ga:source'] = $v['0']; $data['topReferrer'][$key]['ga:visits'] = $v['1']; } //Top 10 page views //$data['topPages']=$this->ga->getTopPage($lastmonth,$now,10); $topPages = $ga->getResultDate('visits', $lastmonth, $now, 'pagePath', '10', '-ga:visits'); foreach ($topPages as $key => $v) { $data['topPages'][$key]['ga:pagePath'] = $v['0']; $data['topPages'][$key]['ga:visits'] = $v['1']; } //Top 10 visitor operating systems //$data['topOs']=$this->ga->getTopOs($lastmonth,$now,10); $topOs = $ga->getResultDate('visits', $lastmonth, $now, 'operatingSystem', '10', '-ga:visits'); foreach ($topOs as $key => $v) { $data['topOs'][$key]['ga:operatingSystem'] = $v['0']; $data['topOs'][$key]['ga:visits'] = $v['1']; } //Top 10 visitor browsers //$data['topBrowsers']=$this->ga->getTopBrowser($lastmonth,$now,10); $topBrowsers = $ga->getResultDate('visits', $lastmonth, $now, 'browser', '10', '-ga:visits'); foreach ($topBrowsers as $key => $v) { $data['topBrowsers'][$key]['ga:browser'] = $v['0']; $data['topBrowsers'][$key]['ga:visits'] = $v['1']; } $this->load->view("ajax_load", $data); }
function index() { //Addlog("read",'ดูรายการจำนวนคนเข้าเว็บไซต์'); //$this->ga->authen('*****@*****.**','F@vourite','ga:75710162'); $ga = new analytics(); if ($_GET) { $now = Date2DB($_GET['date']); } else { $now = date("Y-m-d"); } $lastmonth = date('Y-m-d', strtotime('-29 days', mysql_to_unix($now))); //Last 10 days visitors (for graph) //$data['visits']=$this->ga->getVisits($lastmonth,$now,30); $visits = $ga->getResultDate('visits', $lastmonth, $now); foreach ($visits as $key => $v) { $data['visits'][$key]['ga:date'] = $v['0']; $data['visits'][$key]['ga:visits'] = $v['1']; } //Summery: visitors, unique visit, pageview, time on site, new visits, bounce rates //$data['summery']=$this->ga->getSummery($lastmonth,$now); $data['summery']['ga:visits'] = $ga->getResult('visits', $lastmonth, $now); $data['summery']['ga:visitors'] = $ga->getResult('visitors', $lastmonth, $now); $data['summery']['ga:pageviews'] = $ga->getResult('pageviews', $lastmonth, $now); $data['summery']['ga:timeOnSite'] = $ga->getResult('timeOnSite', $lastmonth, $now); $data['summery']['ga:newVisits'] = $ga->getResult('newVisits', $lastmonth, $now); $data['summery']['ga:bounces'] = $ga->getResult('bounces', $lastmonth, $now); $data['summery']['ga:entrances'] = $ga->getResult('entrances', $lastmonth, $now); //All time summery: visitors, page views //$data['allTimeSummery']=$this->ga->getAllTimeSummery(); $data['allTimeSummery']['ga:visits'] = $ga->getResult('visits', '2005-01-01', $now); $data['allTimeSummery']['ga:pageviews'] = $ga->getResult('pageviews', '2005-01-01', $now); //Top 10 visitor countries //$data['topCountries']=$this->ga->getTopCountry($lastmonth,$now,10); $topCountries = $ga->getResultDate('visits', $lastmonth, $now, 'country', '10', '-ga:visits'); foreach ($topCountries as $key => $v) { $data['topCountries'][$key]['ga:country'] = $v['0']; $data['topCountries'][$key]['ga:visits'] = $v['1']; } //Top 10 search engine keywords //$data['topKeywords'] = $this->ga->getTopKeyword($lastmonth,$now,10); $topKeywords = $ga->getResultDate('visits', $lastmonth, $now, 'keyword', '10', '-ga:visits'); foreach ($topKeywords as $key => $v) { $data['topKeywords'][$key]['ga:keyword'] = $v['0']; $data['topKeywords'][$key]['ga:visits'] = $v['1']; } //Top 10 referrer websites //$data['topReferrer']=$this->ga->getTopReferrer($lastmonth,$now,10); $topReferrer = $ga->getResultDate('visits', $lastmonth, $now, 'source', '10', '-ga:visits'); foreach ($topReferrer as $key => $v) { $data['topReferrer'][$key]['ga:source'] = $v['0']; $data['topReferrer'][$key]['ga:visits'] = $v['1']; } //Top 10 page views //$data['topPages']=$this->ga->getTopPage($lastmonth,$now,10); $topPages = $ga->getResultDate('visits', $lastmonth, $now, 'pagePath', '10', '-ga:visits'); foreach ($topPages as $key => $v) { $data['topPages'][$key]['ga:pagePath'] = $v['0']; $data['topPages'][$key]['ga:visits'] = $v['1']; } //Top 10 visitor operating systems //$data['topOs']=$this->ga->getTopOs($lastmonth,$now,10); $topOs = $ga->getResultDate('visits', $lastmonth, $now, 'operatingSystem', '10', '-ga:visits'); foreach ($topOs as $key => $v) { $data['topOs'][$key]['ga:operatingSystem'] = $v['0']; $data['topOs'][$key]['ga:visits'] = $v['1']; } //Top 10 visitor browsers //$data['topBrowsers']=$this->ga->getTopBrowser($lastmonth,$now,10); $topBrowsers = $ga->getResultDate('visits', $lastmonth, $now, 'browser', '10', '-ga:visits'); foreach ($topBrowsers as $key => $v) { $data['topBrowsers'][$key]['ga:browser'] = $v['0']; $data['topBrowsers'][$key]['ga:visits'] = $v['1']; } $this->template->append_metadata(js_datepicker()); $this->template->build("index", $data); }
include "../" . MODS_DIRECTORY . "/analytics/class.analytics.php"; /* 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; }
<?php // session_start for caching session_start(); require 'analytics.class.php'; try { // construct the class $oAnalytics = new analytics('[username]', '[password]'); // set it up to use caching $oAnalytics->useCache(); $oAnalytics->setProfileByName('[Google analytics accountname]'); // or $oAnalytics->setProfileById('ga:123456'); // set the date range $oAnalytics->setMonth(date('n'), date('Y')); // or $oAnalytics->setDateRange('YYYY-MM-DD', 'YYYY-MM-DD'); 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'))); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage(); }
require 'analytics.class.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['username'], $_POST['password'])){ // set username & password $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; 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'])){
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; } }
require 'analytics.class.php'; require_once 'extensions/wikihow/GoogleSearch.php'; // session_start for caching session_start(); 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");
} // if there asre some problem with esential files if (!file_exists('analytics.class.php') || !file_exists('config.php')) { print array2json(array("status" => 404, "message" => "File not found!")); exit; } include_once 'analytics.class.php'; include_once 'config.php'; // if the config.php is not set 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>"; }