public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // note: not sure why I have to manually install plugin
     \Piwik\Plugin\Manager::getInstance()->loadPlugin('CustomAlerts')->install();
     $result = Fixture::updateDatabase();
     if ($result === false) {
         throw new \Exception("Failed to update pre-2.0 database (nothing to update).");
     }
     // truncate log tables so old data won't be re-archived
     foreach (array('log_visit', 'log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) {
         Db::query("TRUNCATE TABLE " . Common::prefixTable($table));
     }
     // add two visits from same visitor on dec. 29
     $t = Fixture::getTracker(1, '2012-12-29 01:01:30', $defaultInit = true);
     $t->setUrl('http://site.com/index.htm');
     $t->setIp('136.5.3.2');
     Fixture::checkResponse($t->doTrackPageView('incredible title!'));
     $t->setForceVisitDateTime('2012-12-29 03:01:30');
     $t->setUrl('http://site.com/other/index.htm');
     $t->DEBUG_APPEND_URL = '&_idvc=2';
     // make sure visit is marked as returning
     Fixture::checkResponse($t->doTrackPageView('other incredible title!'));
     // launch archiving
     VisitFrequencyApi::getInstance()->get(1, 'year', '2012-12-29');
 }
 protected function makeTracker($idSite, $dateTime, $debugStringAppend = '')
 {
     $tracker = parent::getTracker($idSite, $dateTime, $defaultInit = true);
     if ($this->forceLargeWindowLookBackForVisitor) {
         // Fakes the config value window_look_back_for_visitor tested in TrackerWindowLookBack
         $debugStringAppend .= '&forceLargeWindowLookBackForVisitor=1';
         // Here we force the visitor ID cookie value sent to piwik.php, to create a "unique visitor" for all visits in fixture
         // we do not use setVisitorId(), because we want shouldLookupOneVisitorFieldOnly() to return false for this particular test case
         $debugStringAppend .= '&_id=2f4f673d4732e11d';
     }
     $tracker->setDebugStringAppend($debugStringAppend);
     return $tracker;
 }
Exemple #3
0
 private function trackSomeVisits()
 {
     $nowTimestamp = time();
     // use local tracker so mock location provider can be used
     $t = Fixture::getTracker($this->idSite, $nowTimestamp, $defaultInit = true, $useLocal = false);
     $t->enableBulkTracking();
     for ($i = 0; $i != 20; ++$i) {
         $t->setForceNewVisit();
         $t->setVisitorId(substr(md5($i * 1000), 0, $t::LENGTH_VISITOR_ID));
         $factor = 10;
         if ($i > 15) {
             $factor = 30;
             // make sure first 15 visits are always within 5 minutes to prevent any random fails
         }
         $time = $nowTimestamp - $i * $factor;
         // first visit -> this one is > 5 minutes and should be ignored in one test
         $date = Date::factory($time - 600);
         $t->setForceVisitDateTime($date->getDatetime());
         $t->setUrl("http://piwik.net/space/quest/iv");
         $t->doTrackPageView("Space Quest XV");
         $t->doTrackGoal(1);
         // this one is > 5 minutes and should be ignored in one test
         // second visit
         $date = Date::factory($time - 1);
         $t->setForceVisitDateTime($date->getDatetime());
         $t->setUrl("http://piwik.net/space/quest/iv");
         $t->doTrackPageView("Space Quest XII");
         if ($i % 6 == 0) {
             $t->setForceNewVisit();
             // to test visitors vs visits
         }
         // third visit
         $date = Date::factory($time);
         $t->setForceVisitDateTime($date->getDatetime());
         $t->setUrl("http://piwik.net/grue/{$i}");
         $t->doTrackPageView('It is pitch black...');
         $t->doTrackGoal(2);
     }
     $t->doBulkTrack();
 }
 protected static function _addLogData()
 {
     // tracks visits on the following days:
     // - 2012-01-09
     // - 2012-01-14
     // - 2012-01-19
     // - 2012-01-24 <--- everything before this date is to be purged
     // - 2012-01-29
     // - 2012-02-03
     // - 2012-02-08
     // - 2012-02-13
     // - 2012-02-18
     // - 2012-02-23
     // - 2012-02-28
     // 6 visits in feb, 5 in jan
     // following actions are created:
     // - 'First page view'
     // - 'Second page view'
     // - 'SKU2'
     // - 'Canon SLR'
     // - 'Electronics & Cameras'
     // - for every visit (11 visits total):
     //   - http://whatever.com/_{$daysSinceLastVisit}
     //   - http://whatever.com/42/{$daysSinceLastVisit}
     $start = Date::factory(self::$dateTime);
     self::$idSite = Fixture::createWebsite('2012-01-01', $ecommerce = 1);
     APIGoals::getInstance()->addGoal(self::$idSite, 'match all', 'url', 'http', 'contains');
     $t = Fixture::getTracker(self::$idSite, $start, $defaultInit = true);
     $t->enableBulkTracking();
     $t->setTokenAuth(Fixture::getTokenAuth());
     for ($daysAgo = self::$daysAgoStart; $daysAgo >= 0; $daysAgo -= 5) {
         $dateTime = $start->subDay($daysAgo)->toString();
         $t->setForceVisitDateTime($dateTime);
         $t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)');
         // use $daysAgo to make sure new actions are created for every day and aren't used again.
         // when deleting visits, some of these actions will no longer be referenced in the DB.
         $t->setUrl("http://whatever.com/_{$daysAgo}");
         $t->doTrackPageView('First page view');
         $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.05));
         $t->setUrl("http://whatever.com/42/{$daysAgo}");
         $t->doTrackPageView('Second page view');
         $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.1));
         $t->setUrl("http://whatever.com/event");
         $t->doTrackEvent('Event action', 'event cat', 'daysAgo=' . $daysAgo, 1000);
         $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.2));
         $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR', $category = 'Electronics & Cameras', $price = 1500, $quantity = 1);
         $t->doTrackEcommerceOrder($orderId = '937nsjusu ' . $dateTime, $grandTotal = 1111.11, $subTotal = 1000, $tax = 111, $shipping = 0.11, $discount = 666);
     }
     Fixture::checkBulkTrackingResponse($t->doBulkTrack());
 }