A visit is either NEW or KNOWN. - If a visit is NEW then we process the visitor information (settings, referrers, etc.) and save a new line in the log_visit table. - If a visit is KNOWN then we update the visit row in the log_visit table, updating the number of pages views, time spent, etc. Whether a visit is NEW or KNOWN we also save the action in the DB. One request to the piwik.php script is associated to one action.
Inheritance: implements Piwik\Tracker\VisitInterface
Esempio n. 1
0
 /**
  * Detect whether action is an outlink given host aliases
  *
  * @param Action $action
  * @return bool true if the outlink the visitor clicked on points to one of the known hosts for this website
  */
 protected function detectActionIsOutlinkOnAliasHost(Action $action, $idSite)
 {
     $decodedActionUrl = $action->getActionUrl();
     $actionUrlParsed = @parse_url($decodedActionUrl);
     if (!isset($actionUrlParsed['host'])) {
         return false;
     }
     return Visit::isHostKnownAliasHost($actionUrlParsed['host'], $idSite);
 }
Esempio n. 2
0
 /**
  * Detect whether action is an outlink given host aliases
  *
  * @param Action $action
  * @return bool true if the outlink the visitor clicked on points to one of the known hosts for this website
  */
 public static function detectActionIsOutlinkOnAliasHost(Action $action, $idSite)
 {
     if ($action->getActionType() != Action::TYPE_OUTLINK) {
         return false;
     }
     $decodedActionUrl = $action->getActionUrl();
     $actionUrlParsed = @parse_url($decodedActionUrl);
     if (!isset($actionUrlParsed['host'])) {
         return false;
     }
     return Visit::isHostKnownAliasHost($actionUrlParsed['host'], $idSite);
 }
 private function trackVisits()
 {
     $dateTime = $this->dateTime;
     $idSite = $this->idSite;
     $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
     // First, some basic tests
     self::settingInvalidVisitorIdShouldThrow($t);
     // We create VISITOR A
     $t->setUrl('http://example.org/index.htm');
     $t->setVisitorId(Visit::generateUniqueVisitorId());
     self::checkResponse($t->doTrackPageView('incredible title!'));
     // VISITOR B: few minutes later, we trigger the same tracker but with a custom visitor ID,
     // => this will create a new visit B
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.05)->getDatetime());
     $t->setUrl('http://example.org/index2.htm');
     $t->setVisitorId(Visit::generateUniqueVisitorId());
     self::checkResponse($t->doTrackPageView('incredible title!'));
     // This new visit B will have 2 page views
     $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.1)->getDatetime());
     $t->setUrl('http://example.org/index3.htm');
     self::checkResponse($t->doTrackPageView('incredible title!'));
     // total = 2 visitors, 3 page views
 }
Esempio n. 4
0
 private function prepareVisitWithRequest($requestParams, $requestDate)
 {
     $request = new Request($requestParams);
     $request->setCurrentTimestamp(Date::factory($requestDate)->getTimestamp());
     $visit = new Visit();
     $visit->setRequest($request);
     $visit->handle();
     return array($visit, $request);
 }
Esempio n. 5
0
 protected function sendRequest($url, $method = 'GET', $data = null, $force = false)
 {
     if ($this->DEBUG_APPEND_URL) {
         $url .= $this->DEBUG_APPEND_URL;
     }
     // if doing a bulk request, store the url
     if ($this->doBulkRequests && !$force) {
         $this->storedTrackingActions[] = $url;
         return true;
     }
     if ($method == 'POST') {
         $requests = array();
         foreach ($this->storedTrackingActions as $action) {
             $requests[] = $this->parseUrl($action);
         }
         $testEnvironmentArgs = array();
     } else {
         $testEnvironmentArgs = $this->parseUrl($url);
         $requests = array($testEnvironmentArgs);
     }
     // unset cached values
     Cache::$cache = null;
     Tracker\Visit::$dimensions = null;
     // save some values
     $plugins = Config::getInstance()->Plugins['Plugins'];
     $oldTrackerConfig = Config::getInstance()->Tracker;
     \Piwik\Plugin\Manager::getInstance()->unloadPlugins();
     // modify config
     \Piwik\SettingsServer::setIsTrackerApiRequest();
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
     Tracker::$initTrackerMode = false;
     Tracker::setTestEnvironment($testEnvironmentArgs, $method);
     // set language
     $oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage;
     // set user agent
     $oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $_SERVER['HTTP_USER_AGENT'] = $this->userAgent;
     // set cookie
     $oldCookie = $_COOKIE;
     //        parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE);
     // do tracking and capture output
     ob_start();
     $localTracker = new Tracker();
     $request = new Tracker\RequestSet();
     $request->setRequests($requests);
     \Piwik\Plugin\Manager::getInstance()->loadTrackerPlugins();
     $handler = Tracker\Handler\Factory::make();
     $response = $localTracker->main($handler, $request);
     if (!is_null($response)) {
         echo $response;
     }
     $output = ob_get_contents();
     ob_end_clean();
     // restore vars
     Config::getInstance()->Tracker = $oldTrackerConfig;
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
     $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
     $_COOKIE = $oldCookie;
     $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
     \Piwik\SettingsServer::setIsNotTrackerApiRequest();
     unset($_GET['bots']);
     // reload plugins
     \Piwik\Plugin\Manager::getInstance()->loadPlugins($plugins);
     return $output;
 }
Esempio n. 6
0
 private function trackVisits($visitorCount, $setIp = false, $useLocal = true, $doBulk = false)
 {
     static $calledCounter = 0;
     $calledCounter++;
     $dateTime = $this->dateTime;
     $idSite = $this->idSite;
     if ($useLocal) {
         Cache::getTransientCache()->flushAll();
         // make sure dimension cache is empty between local tracking runs
         Visit::$dimensions = null;
     }
     // use local tracker so mock location provider can be used
     $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useLocal);
     if ($doBulk) {
         $t->enableBulkTracking();
     }
     $t->setTokenAuth(self::getTokenAuth());
     for ($i = 0; $i != $visitorCount; ++$i) {
         $t->setVisitorId(substr(md5($i + $calledCounter * 1000), 0, $t::LENGTH_VISITOR_ID));
         if ($setIp) {
             $t->setIp(current($this->ips));
             next($this->ips);
         } else {
             $t->setIp("1.2.4.{$i}");
         }
         // first visit
         $date = Date::factory($dateTime)->addDay($i);
         $t->setForceVisitDateTime($date->getDatetime());
         $t->setUrl("http://piwik.net/grue/lair");
         $t->setCustomVariable(1, 'Cvar 1 name', 'Cvar1 value is ' . $i, 'visit');
         $t->setCustomVariable(5, 'Cvar 5 name', 'Cvar5 value is ' . $i, 'visit');
         $t->setCustomVariable(2, 'Cvar 2 PAGE name', 'Cvar2 PAGE value is ' . $i, 'page');
         $t->setCustomVariable(5, 'Cvar 5 PAGE name', 'Cvar5 PAGE value is ' . $i, 'page');
         $r = $t->doTrackPageView('It\'s <script> pitch black...');
         if (!$doBulk) {
             self::checkResponse($r);
         }
         // second visit
         $date = $date->addHour(1);
         $t->setForceVisitDateTime($date->getDatetime());
         $t->setUrl("http://piwik.net/space/quest/iv");
         // Manually record some data
         $t->setDebugStringAppend('&_idts=' . $date->subDay(100)->getTimestampUTC() . '&_ects=' . $date->subDay(50)->getTimestampUTC() . '&_viewts=' . $date->subDay(10)->getTimestampUTC() . '&_idvc=5');
         $r = $t->doTrackPageView("Space Quest XII");
         if (!$doBulk) {
             self::checkResponse($r);
         }
         // Track site search (for AutoSuggestAPI test)
         // Only for half visitors so they don't all have a "site search" as last action and some of them have a standard page view as last action
         $date = $date->addHour(0.1);
         $t->setForceVisitDateTime($date->getDatetime());
         if ($i % 2 == 0) {
             $r = $t->doTrackSiteSearch('Bring on the party', 'CAT');
         }
         if (!$doBulk) {
             self::checkResponse($r);
         }
         $date = $date->addHour(0.2);
         $t->setForceVisitDateTime($date->getDatetime());
         $r = $t->doTrackGoal($this->idGoal2);
         if (!$doBulk) {
             self::checkResponse($r);
         }
         $date = $date->addHour(0.05);
         $t->setForceVisitDateTime($date->getDatetime());
         $t->doTrackAction('http://example.org/path/file' . $i . '.zip', "download");
         if (!$doBulk) {
             self::checkResponse($r);
         }
         $date = $date->addHour(0.05);
         $t->setForceVisitDateTime($date->getDatetime());
         $r = $t->doTrackAction('http://example-outlink.org/' . $i . '.html', "link");
         if (!$doBulk) {
             self::checkResponse($r);
         }
         $date = $date->addHour(0.05);
         $t->setForceVisitDateTime($date->getDatetime());
         $r = $t->doTrackEvent('Cat' . $i, 'Action' . $i, 'Name' . $i, 345.678 + $i);
         if (!$doBulk) {
             self::checkResponse($r);
         }
     }
     if ($doBulk) {
         self::checkBulkTrackingResponse($t->doBulkTrack());
     }
 }
Esempio n. 7
0
 /**
  * We have previously tried to detect the campaign variables in the URL
  * so at this stage, if the referrer host is the current host,
  * or if the referrer host is any of the registered URL for this website,
  * it is considered a direct entry
  * @return bool
  */
 protected function detectReferrerDirectEntry()
 {
     if (!empty($this->referrerHost)) {
         // is the referrer host the current host?
         if (isset($this->currentUrlParse['host'])) {
             $currentHost = Common::mb_strtolower($this->currentUrlParse['host'], 'UTF-8');
             if ($currentHost == Common::mb_strtolower($this->referrerHost, 'UTF-8')) {
                 $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
                 return true;
             }
         }
         if (Visit::isHostKnownAliasHost($this->referrerHost, $this->idsite)) {
             $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
             return true;
         }
     }
     return false;
 }
 public function handleNewVisit($visitor, $action, $visitIsConverted)
 {
     parent::handleNewVisit($visitor, $action, $visitIsConverted);
 }
 private function setDimensionsWithOnNewVisit($dimensionOnNewVisitResults)
 {
     $dimensions = array();
     foreach ($dimensionOnNewVisitResults as $onNewVisitResult) {
         $dim = $this->getMock('Piwik\\Plugin\\Dimension', array('shouldForceNewVisit', 'getColumnName'));
         $dim->expects($this->any())->method('shouldForceNewVisit')->will($this->returnValue($onNewVisitResult));
         $dimensions[] = $dim;
     }
     $cache = Cache::getTransientCache();
     $cache->save(CacheId::pluginAware('VisitDimensions'), $dimensions);
     Visit::$dimensions = null;
 }