1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Fixtures;
use Piwik\Date;
use Piwik\Tests\Framework\Fixture;
/**
* Adds one website and tracks several visits from one visitor on
* different days that span about a month apart.
*/
class VisitsOverSeveralDays extends Fixture
{
public $dateTimes = array(
'2010-12-14 01:00:00',
'2010-12-15 01:00:00',
'2010-12-25 01:00:00',
'2011-01-15 01:00:00',
'2011-01-16 01:00:00',
);
public $idSite = 1;
public $idSite2 = 2;
public $forceLargeWindowLookBackForVisitor = false;
// one per visit
public $referrerUrls = array(
'http://facebook.com/whatever',
'http://www.facebook.com/another/path',
'http://fb.me/?q=sdlfjs&n=slfjsd',
'http://twitter.com/whatever2',
'http://www.twitter.com/index?a=2334',
'http://t.co/id/?y=dsfs',
'http://www.flickr.com',
'http://xanga.com',
'http://skyrock.com',
'http://mixi.jp',
);
public function setUp(): void
{
$this->setUpWebsitesAndGoals();
$this->trackVisits();
}
public function tearDown(): void
{
// empty
}
private function setUpWebsitesAndGoals()
{
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTimes[0], $ecommerce = 0, $siteName = 'Site AAAAAA');
}
if (!self::siteCreated($idSite = 2)) {
self::createWebsite($this->dateTimes[0], $ecommerce = 0, $siteName = 'SITE BBbbBB');
}
}
private function trackVisits()
{
$dateTimes = $this->dateTimes;
$days = 0;
$ridx = 0;
foreach ($dateTimes as $dateTime) {
$days++;
// Fake the visit count cookie
$debugStringAppend = "&_idvc=$days";
$visitor = $this->makeTracker($this->idSite, $dateTime, $debugStringAppend);
// FIRST VISIT THIS DAY
$visitor->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.1)->getDatetime());
$visitor->setUrl('http://example.org/homepage');
$visitor->setUrlReferrer($this->referrerUrls[$ridx++]);
self::checkResponse($visitor->doTrackPageView('ou pas'));
// Test change the IP, the visit should not be split but recorded to the same idvisitor
$visitor->setIp('200.1.15.22');
$visitor->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.2)->getDatetime());
$urlWithThreeSubdirectories = 'http://example.org/sub1/sub2/sub3/news';
$visitor->setUrl($urlWithThreeSubdirectories);
self::checkResponse($visitor->doTrackPageView('ou pas'));
// SECOND VISIT THIS DAY
$visitor->setForceVisitDateTime(Date::factory($dateTime)->addHour(1)->getDatetime());
$visitor->setUrl('http://example.org/news');
$visitor->setUrlReferrer($this->referrerUrls[$ridx++]);
self::checkResponse($visitor->doTrackPageView('ou pas'));
if ($days <= 3) {
$visitor = $this->makeTracker($this->idSite2, $dateTime);
$visitor->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.1)->getDatetime());
$visitor->setUrl('http://example.org/homepage');
$visitor->setUrlReferrer($this->referrerUrls[$ridx - 1]);
self::checkResponse($visitor->doTrackPageView('Second website'));
}
}
}
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;
}
}
|