예제 #1
0
 function __construct($ipAddress, $startTime)
 {
     global $configArray;
     if (!isset($configArray)) {
         die("You must load configuration before creating a tracker");
     }
     global $interface;
     if (!isset($interface)) {
         die("You must setup the interface before creating a tracker");
     }
     //Make sure that we don't track visits from bots
     if (BotChecker::isRequestFromBot() == true) {
         //$logger->log("Disabling logging because the request is from a bot", PEAR_LOG_DEBUG);
         $this->trackingDisabled = true;
         $this->finished = true;
         return;
     }
     //Check to see if analytics is enabled
     if (isset($configArray['System']['enableAnalytics']) && $configArray['System']['enableAnalytics'] == false) {
         $this->trackingDisabled = true;
         return;
     }
     //Check to see if we are in maintenance mode
     if (isset($configArray['System']['available']) && $configArray['System']['available'] == false) {
         $this->trackingDisabled = true;
         return;
     }
     $session = new Analytics_Session();
     //disable error handler since the tables may not be installed yet.
     disableErrorHandler();
     $sessionId = session_id();
     $session->session_id = $sessionId;
     if ($session->find(true)) {
         $this->session = $session;
         if ($this->session->ip != $ipAddress) {
             $this->session->ip = $ipAddress;
             $this->doGeoIP();
         }
     } else {
         $this->session = $session;
         $this->session->sessionStartTime = $startTime;
         $this->session->lastRequestTime = $startTime;
         $this->session->ip = $ipAddress;
         $this->doGeoIP();
         $this->session->insert();
     }
     $this->pageView = new Analytics_PageView();
     $this->pageView->sessionId = $this->session->id;
     $this->pageView->pageStartTime = $startTime;
     $this->pageView->fullUrl = $_SERVER['REQUEST_URI'];
     enableErrorHandler();
 }
예제 #2
0
 /**
  * Recent activity includes users, searches done, events, and page views
  */
 function getRecentActivity()
 {
     global $analytics;
     $interval = isset($_REQUEST['interval']) ? $_REQUEST['interval'] : 10;
     $curTime = time();
     $activityByMinute = array();
     $analyticsSession = $analytics->getSessionFilters();
     if ($analyticsSession == null) {
         $analyticsSession = new Analytics_Session();
     }
     $analyticsSession->selectAdd('count(id) as numActiveUsers');
     $analyticsSession->whereAdd('lastRequestTime > ' . ($curTime - $interval));
     //$analyticsSession->whereAdd("lastRequestTime <= $curTime");
     if ($analyticsSession->find(true)) {
         $activityByMinute['activeUsers'] = $analyticsSession->numActiveUsers;
     } else {
         $activityByMinute['activeUsers'] = 0;
     }
     $pageView = new Analytics_PageView();
     $pageView->selectAdd('count(id) as numPageViews');
     $pageView->whereAdd("pageEndTime > " . ($curTime - $interval));
     //$pageView->whereAdd("pageEndTime <= $curTime");
     if ($pageView->find(true)) {
         $activityByMinute['pageViews'] = $pageView->numPageViews;
     } else {
         $activityByMinute['pageViews'] = 0;
     }
     $searches = new Analytics_Search();
     $searches->selectAdd('count(id) as numSearches');
     $searches->whereAdd("searchTime > " . ($curTime - $interval));
     //$searches->whereAdd("searchTime <= $curTime");
     if ($searches->find(true)) {
         $activityByMinute['searches'] = $searches->numSearches;
     } else {
         $activityByMinute['searches'] = 0;
     }
     $events = new Analytics_Event();
     $events->selectAdd('count(id) as numEvents');
     $events->whereAdd("eventTime > " . ($curTime - $interval));
     //$events->whereAdd("eventTime <= $curTime");
     if ($events->find(true)) {
         $activityByMinute['events'] = $events->numEvents;
     } else {
         $activityByMinute['events'] = 0;
     }
     return $activityByMinute;
 }
예제 #3
0
 function getSessionFilter($label, $field)
 {
     $analyticsSession = new Analytics_Session();
     $analyticsSession->selectAdd();
     $analyticsSession->selectAdd("distinct({$field})");
     $analyticsSession->find();
     $filter = array();
     $filter['label'] = $label;
     $filter['field'] = $field;
     while ($analyticsSession->fetch()) {
         if ($analyticsSession->{$field} == null) {
             $filter['values']['null'] = 'unset';
         } else {
             $filter['values'][$analyticsSession->{$field}] = $analyticsSession->{$field};
         }
     }
     natcasesort($filter['values']);
     return $filter;
 }