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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
<?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\Plugins\Goals\API as APIGoals;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Tests\Framework\Fixture;
/**
* Adds two websites and tracks visits from two visitors on different days.
*/
class TwoSitesTwoVisitorsDifferentDays extends Fixture
{
public $idSite1 = 1;
public $idSite2 = 2;
public $idGoal1 = 1;
public $idGoal2 = 2;
public $dateTime = '2010-01-03 11:22:33';
public $allowConversions = false;
const URL_IS_GOAL_WITH_CAMPAIGN_PARAMETERS = 'http://example.org/index.htm?pk_campaign=goal-matching-url-parameter';
public function setUp(): void
{
$this->setUpWebsitesAndGoals();
self::setUpScheduledReports($this->idSite1);
$this->trackVisits();
}
public function tearDown(): void
{
// empty
}
private function setUpWebsitesAndGoals()
{
$ecommerce = $this->allowConversions ? 1 : 0;
// tests run in UTC, the Tracker in UTC
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime, $ecommerce, "Site 1");
}
if (!self::siteCreated($idSite = 2)) {
self::createWebsite($this->dateTime, 0, "Site 2");
}
if ($this->allowConversions) {
if (!self::goalExists($idSite = 1, $idGoal = 1)) {
APIGoals::getInstance()->addGoal($this->idSite1, 'all', 'url', 'http', 'contains', false, 5);
}
if (!self::goalExists($idSite = 1, $idGoal = 2)) {
APIGoals::getInstance()->addGoal($this->idSite2, 'all', 'url', 'http', 'contains');
}
if (!self::goalExists($idSite = 1, $idGoal = 3)) {
APIGoals::getInstance()->addGoal($this->idSite1, 'matching URL with campaign parameter', 'url', self::URL_IS_GOAL_WITH_CAMPAIGN_PARAMETERS, 'contains');
}
}
APISitesManager::getInstance()->updateSite(
$this->idSite1, "Site 1", $urls = null, $ecommerce = null, $siteSearch = null,
$searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null,
$excludedQueryParameters = null, $timezone = null, $currency = null, $group = null,
$startDate = null, $excludedUserAgents = null, $keepURLFragments = 2); // KEEP_URL_FRAGMENT_NO No for idSite 1
APISitesManager::getInstance()->updateSite(
$this->idSite2, "Site 2", $urls = null, $ecommerce = null, $siteSearch = null,
$searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null,
$excludedQueryParameters = null, $timezone = null, $currency = null, $group = null,
$startDate = null, $excludedUserAgents = null, $keepURLFragments = 1); // KEEP_URL_FRAGMENT_YES Yes for idSite 2
}
public function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite1;
$idSite2 = $this->idSite2;
$this->trackVisitsSite1($idSite, $dateTime);
$this->trackVisitsSite2($idSite2, $dateTime);
}
/**
* @param $idSite
* @param $dateTime
*/
private function trackVisitsSite1($idSite, $dateTime)
{
// -
// First visitor on Idsite 1: two page views
$datetimeSpanOverTwoDays = '2010-01-03 23:55:00';
$visitorA = self::getTracker($idSite, $datetimeSpanOverTwoDays, $defaultInit = true);
$visitorA->setUrlReferrer('http://referrer.com/page.htm?param=valuewith some spaces');
$visitorA->setUrl('http://example.org/index.htm#ignoredFragment');
$visitorA->DEBUG_APPEND_URL = '&_idts=' . Date::factory($datetimeSpanOverTwoDays)->getTimestamp();
$visitorA->setGenerationTime(123);
self::checkResponse($visitorA->doTrackPageView('first page view'));
$visitorA->setForceVisitDateTime(Date::factory($datetimeSpanOverTwoDays)->addHour(0.1)->getDatetime());
// testing with empty URL and empty page title
$visitorA->setUrl(' ');
$visitorA->setGenerationTime(223);
self::checkResponse($visitorA->doTrackPageView(' '));
// -
// Second new visitor on Idsite 1: one page view
$visitorB = self::getTracker($idSite, $dateTime, $defaultInit = true);
$visitorB->enableBulkTracking();
$visitorB->setIp('100.52.156.83');
$visitorB->setResolution(800, 300);
$visitorB->setForceVisitDateTime(Date::factory($dateTime)->addHour(1)->getDatetime());
$visitorB->setUrlReferrer('');
$visitorB->setUserAgent('Opera/9.63 (Windows NT 5.1; U; en) Presto/2.1.1');
$visitorB->setUrl('http://example.org/products');
$visitorB->DEBUG_APPEND_URL = '&_idts=' . Date::factory($dateTime)->addHour(1)->getTimestamp();
$visitorB->setGenerationTime(153);
self::assertTrue($visitorB->doTrackPageView('first page view'));
// -
// Second visitor again on Idsite 1: 2 page views 2 days later, 2010-01-05
// If you are thinking of *decreasing* this value, just DON'T (it's important for our test case)
$daysToGenerateVisitsFor = 10;
for($days = 2; $days < $daysToGenerateVisitsFor; $days++) {
$hoursOffset = $days * 24;
$visitorB->setForceVisitDateTime(Date::factory($dateTime)->addHour($hoursOffset)->getDatetime());
// visitor_returning is set to 1 only when visit count more than 1
// Temporary, until we implement 1st party cookies in MatomoTracker
$visitorB->DEBUG_APPEND_URL .= '&_idvc=2&_viewts=' . Date::factory($dateTime)->getTimestamp();
$protocol = (0 === $days % 2) ? 'http' : 'https';
$visitorB->setUrlReferrer($protocol . '://referrer.com/Other_Page.htm');
if( in_array($days, array(2,3,4,$daysToGenerateVisitsFor-1)) ) {
$visitorB->setUrl( self::URL_IS_GOAL_WITH_CAMPAIGN_PARAMETERS );
} else {
$visitorB->setUrl('http://example.org/index.htm');
}
$visitorB->setGenerationTime(323);
self::assertTrue($visitorB->doTrackPageView('second visitor/two days later/a new visit'));
// Second page view 6 minutes later
$visitorB->setForceVisitDateTime(Date::factory($dateTime)->addHour($hoursOffset)->addHour(0.1)->getDatetime());
$visitorB->setUrl('http://example.org/thankyou');
$visitorB->setGenerationTime(173);
self::assertTrue($visitorB->doTrackPageView('second visitor/two days later/second page view'));
// testing a strange combination causing an error in r3767
$visitorB->setForceVisitDateTime(Date::factory($dateTime)->addHour($hoursOffset)->addHour(0.2)->getDatetime());
self::assertTrue($visitorB->doTrackAction('mailto:test@example.org', 'link'));
$visitorB->setForceVisitDateTime(Date::factory($dateTime)->addHour($hoursOffset)->addHour(0.25)->getDatetime());
self::assertTrue($visitorB->doTrackAction('mailto:test@example.org/strangelink', 'link'));
// Actions.getPageTitle tested with this title
$visitorB->setForceVisitDateTime(Date::factory($dateTime)->addHour($hoursOffset)->addHour(0.25)->getDatetime());
$visitorB->setGenerationTime(452);
self::assertTrue($visitorB->doTrackPageView('Checkout / Purchasing...'));
self::checkBulkTrackingResponse($visitorB->doBulkTrack());
}
}
/**
* @param $idSite2
* @param $dateTime
*/
private function trackVisitsSite2($idSite2, $dateTime)
{
// -
// First visitor on Idsite 2: one page view, with Website referrer
$visitorAsite2 = self::getTracker($idSite2, Date::factory($dateTime)->addHour(24)->getDatetime(), $defaultInit = true);
$visitorAsite2->setUserAgent('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;)');
$visitorAsite2->setUrlReferrer('http://only-homepage-referrer.com/');
$visitorAsite2->setUrl('http://example2.com/home#notIgnoredFragment#');
$visitorAsite2->DEBUG_APPEND_URL = '&_idts=' . Date::factory($dateTime)->addHour(24)->getTimestamp();
$visitorAsite2->setGenerationTime(193);
self::checkResponse($visitorAsite2->doTrackPageView('Website 2 page view'));
// test with invalid URL
$visitorAsite2->setUrl('this is invalid url');
// and an empty title
$visitorAsite2->setGenerationTime(203);
self::checkResponse($visitorAsite2->doTrackPageView(''));
// track a page view with a domain alias to test the aggregation of both actions
$visitorAsite2->setUrl('http://example2alias.org/home#notIgnoredFragment#');
$visitorAsite2->setGenerationTime(503);
self::checkResponse($visitorAsite2->doTrackPageView(''));
}
}
|