Beispiel #1
0
 function __construct(Request $request, Tracker\Settings $settings, $visitorInfo = array(), $customVariables = null)
 {
     $this->request = $request;
     $this->visitorInfo = $visitorInfo;
     $this->customVariables = $customVariables;
     $this->userInfo = $settings->getInfo();
 }
 public function processRequestParams(VisitProperties $visitProperties, Request $request)
 {
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $visitProperties->setProperty('location_ip', $request->getIp());
     // TODO: move VisitExcluded logic to here (or move to service class stored in DI)
     $excluded = new VisitExcluded($request, $visitProperties->getProperty('location_ip'));
     if ($excluded->isExcluded()) {
         return true;
     }
     // visitor recognition
     $visitorId = $this->userSettings->getConfigId($request, $visitProperties->getProperty('location_ip'));
     $request->setMetadata('CoreHome', 'visitorId', $visitorId);
     $isKnown = $this->visitorRecognizer->findKnownVisitor($visitorId, $visitProperties, $request);
     $request->setMetadata('CoreHome', 'isVisitorKnown', $isKnown);
     $isNewVisit = $this->isVisitNew($visitProperties, $request);
     $request->setMetadata('CoreHome', 'isNewVisit', $isNewVisit);
     return false;
 }
Beispiel #3
0
 public function processRequestParams(VisitProperties $visitProperties, Request $request)
 {
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $visitProperties->setProperty('location_ip', $request->getIp());
     $excluded = new VisitExcluded($request);
     if ($excluded->isExcluded()) {
         return true;
     }
     $privacyConfig = new PrivacyManagerConfig();
     $ip = $request->getIpString();
     if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $visitProperties->getProperty('location_ip');
     }
     // visitor recognition
     $visitorId = $this->userSettings->getConfigId($request, $ip);
     $request->setMetadata('CoreHome', 'visitorId', $visitorId);
     $isKnown = $this->visitorRecognizer->findKnownVisitor($visitorId, $visitProperties, $request);
     $request->setMetadata('CoreHome', 'isVisitorKnown', $isKnown);
     $isNewVisit = $this->isVisitNew($visitProperties, $request);
     $request->setMetadata('CoreHome', 'isNewVisit', $isNewVisit);
     return false;
 }
 public function popout()
 {
     header("Access-Control-Allow-Origin: *");
     $params = UrlHelper::getArrayFromQueryString($_SERVER['QUERY_STRING']);
     $request = new Tracker\Request($params);
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $ip = $request->getIp();
     $visitorInfo['location_ip'] = $ip;
     /**
      * Triggered after visits are tested for exclusion so plugins can modify the IP address
      * persisted with a visit.
      *
      * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses.
      *
      * @param string &$ip The visitor's IP address.
      */
     Piwik::postEvent('Tracker.setVisitorIp', array(&$visitorInfo['location_ip']));
     /***
      * Visitor recognition
      */
     $settings = new Tracker\Settings($request, $visitorInfo['location_ip']);
     $visitor = new Visitor($request, $settings->getConfigId(), $visitorInfo);
     $visitor->recognize();
     $visitorInfo = $visitor->getVisitorInfo();
     if (!isset($visitorInfo['location_browser_lang'])) {
         return "Who are you ?";
     }
     $idSite = Common::getRequestVar('idsite', null, 'int');
     $conversation = new ChatConversation($idSite, bin2hex($visitorInfo['idvisitor']));
     /***
      * Segment recognition
      */
     foreach (ChatAutomaticMessage::getAll($idSite) as $autoMsg) {
         $segment = ChatSegment::get($autoMsg['segmentID']);
         $fetchSegment = new Segment($segment['definition'], array($idSite));
         $query = $fetchSegment->getSelectQuery("idvisitor", "log_visit", "log_visit.idvisitor = ?", array($visitorInfo['idvisitor']));
         $rows = Db::fetchAll($query['sql'], $query['bind']);
         if (count($rows) == 0) {
             continue;
         }
         if ($autoMsg['segmentID'] != $segment['idsegment']) {
             continue;
         }
         $getAlreadyReceivedMsg = $conversation->getAutomaticMessageReceivedById($autoMsg['id']);
         if (count($getAlreadyReceivedMsg) > 0) {
             // If the AutoMsg is a "one shot"
             if ($autoMsg['frequency'] == 0) {
                 continue;
             }
             if ($autoMsg['frequency'] != 0) {
                 // Now, we gonna try to define when the last AutoMsg received has been sent
                 list($freqTime, $freqScale) = explode('|', $autoMsg['frequency']);
                 if ($freqScale == "w") {
                     $dayMultiplier = 7;
                 } elseif ($freqScale == "m") {
                     $dayMultiplier = 30;
                 } else {
                     $dayMultiplier = 1;
                 }
                 $secToWait = 3600 * 24 * $freqTime * $dayMultiplier;
                 // Is it older than the time range needed to wait ?
                 if ($getAlreadyReceivedMsg[0]['microtime'] + $secToWait > microtime(true)) {
                     continue;
                 }
             }
         }
         $conversation->sendMessage($autoMsg['message'], $autoMsg['transmitter'], $autoMsg['id']);
     }
     $view = new View('@Chat/popout.twig');
     $view->idvisitor = bin2hex($visitorInfo['idvisitor']);
     $view->idsite = $idSite;
     $view->timeLimit = time() - 2 * 60 * 60;
     $view->isStaffOnline = ChatPiwikUser::isStaffOnline();
     $view->siteUrl = ChatSite::getMainUrl($idSite);
     $view->lang = $visitorInfo['location_browser_lang'];
     return $view->render();
 }