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
|
<?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\Plugins\IntranetMeasurable\tests\Fixtures;
use Piwik\Date;
use Piwik\Plugins\IntranetMeasurable\Type;
use Piwik\Tests\Framework\Fixture;
/**
* Generates tracker testing data for our TrackingTest
*
* This Simple fixture adds one website and tracks one visit with couple pageviews and an ecommerce conversion
*/
class IntranetSitesWithVisits extends Fixture
{
public $dateTime = '2013-01-23 01:23:45';
public $idSite = 1;
public $idSiteNotIntranet = 2;
public function setUp()
{
$this->setUpWebsites();
$this->trackVisits($this->idSite);
$this->trackVisits($this->idSiteNotIntranet);
}
public function tearDown()
{
// empty
}
private function setUpWebsites()
{
if (!self::siteCreated($this->idSite)) {
Fixture::createWebsite(
'2014-01-02 03:04:05', $ecommerce = 0, $siteName = false, $siteUrl = false,
$siteSearch = 1, $searchKeywordParameters = null,
$searchCategoryParameters = null, $timezone = null, Type::ID
);
}
if (!self::siteCreated($this->idSiteNotIntranet)) {
Fixture::createWebsite('2014-01-02 03:04:05');
}
}
private function configureSameDevice(\PiwikTracker $t)
{
// to make purpose of test more clear we configure the device partially...
$t->setIp('56.11.55.70');
$t->setResolution(500, 200);
$t->setPlugins(true, false, true, false, true);
$t->setUserAgent('Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1');
return $t;
}
protected function trackVisits($idSite)
{
// two visits... intranet will trust visitorId and generate two visits
// regular website will only generate one visit and prefer configId
$t = self::getTracker($idSite, $this->dateTime, $defaultInit = true);
$this->configureSameDevice($t);
$t->randomVisitorId = '1234567890123456';
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.1)->getDatetime());
$t->setUrl('http://example.com/');
self::checkResponse($t->doTrackPageView('Viewing homepage'));
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
$t->setUrl('http://example.com/sub/page');
self::checkResponse($t->doTrackPageView('Second page view'));
// different IP and different device but same visitor id... should still match this as unique visitor for intranet site
// but not the other site
$t = self::getTracker($idSite, $this->dateTime, $defaultInit = true);
$this->configureSameDevice($t);
$t->randomVisitorId = '1234567890123457';
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.1)->getDatetime());
$t->setUrl('http://example.com/sub/page');
self::checkResponse($t->doTrackPageView('Viewing homepage'));
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.2)->getDatetime());
$t->setUrl('http://example.com/?search=this is a site search query');
self::checkResponse($t->doTrackPageView('Site search query'));
}
}
|