« git@code.facil.services:facil/stats-facil.git » n'existait pas sur « 456c45693eeb2df33edc495f61bc91ea5f06eada »
Newer
Older
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
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id$
*/
/**
* Tests w/ two visits & custom variables.
*/
class Test_Piwik_Integration_TwoVisitsWithCustomVariables extends IntegrationTestCase
{
protected $dateTime = '2010-01-03 11:22:33';
protected $width = 1111;
protected $height = 222;
protected $idSite = 1;
protected $idGoal1 = 1;
protected $idGoal2 = 2;
protected $visitorId = null;
protected $useEscapedQuotes = true;
protected $doExtraQuoteTests = true;
public function getApiForTesting()
{
$apiToCall = array('VisitsSummary.get', 'CustomVariables.getCustomVariables');
$return = array(
array($apiToCall, array('idSite' => 'all',
'date' => $this->dateTime,
'periods' => array('day', 'week'),
'setDateLastN' => true)),
);
return $return;
}
/**
* @dataProvider getApiForTesting
* @group Integration
* @group TwoVisitsWithCustomVariables
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getOutputPrefix()
{
return 'twoVisitsWithCustomVariables';
}
public function setUp()
{
parent::setUp();
// tests run in UTC, the Tracker in UTC
$this->createWebsite($this->dateTime);
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'triggered js', 'manually', '', '');
Piwik_Goals_API::getInstance()->addGoal($this->idSite, 'second goal', 'manually', '', '');
$this->trackVisits();
}
protected function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$idGoal = $this->idGoal1;
$idGoal2 = $this->idGoal2;
ob_start();
$visitorA = $this->getTracker($idSite, $dateTime, $defaultInit = true);
// Used to test actual referer + keyword position in Live!
$visitorA->setUrlReferrer(urldecode('http://www.google.com/url?sa=t&source=web&cd=1&ved=0CB4QFjAA&url=http%3A%2F%2Fpiwik.org%2F&rct=j&q=this%20keyword%20should%20be%20ranked&ei=V8WfTePkKKLfiALrpZWGAw&usg=AFQjCNF_MGJRqKPvaKuUokHtZ3VvNG9ALw&sig2=BvKAdCtNixsmfNWXjsNyMw'));
// no campaign, but a search engine to attribute the goal conversion to
$attribution = array(
'',
'',
1302306504,
'http://www.google.com/search?q=piwik&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a'
);
$visitorA->setAttributionInfo(json_encode($attribution));
$visitorA->setResolution($this->width, $this->height);
// At first, visitor custom var is set to LoggedOut
$visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime());
$visitorA->setUrl('http://example.org/homepage');
$visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut');
$this->checkResponse($visitorA->doTrackPageView('Homepage'));
$this->checkResponse($visitorA->doTrackGoal($idGoal2, 0));
// After login, set to LoggedIn, should overwrite previous value
$visitorA->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.2)->getDatetime());
$visitorA->setUrl('http://example.org/user/profile');
$visitorA->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedIn');
$visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = 'Loggedin', $scope = 'page');
if ($this->useEscapedQuotes) {
$lookingAtProfile = 'looking at "profile page"';
} else {
$lookingAtProfile = 'looking at profile page';
}
$visitorA->setCustomVariable($id = 5, $name = 'Status user', $value = $lookingAtProfile, $scope = 'page');
$this->checkResponse($visitorA->doTrackPageView('Profile page'));
$visitorA->setCustomVariable($id = 2, $name = 'SET WITH EMPTY VALUE', $value = '');
$visitorA->setCustomVariable($id = 1, $name = 'Language', $value = 'FR', $scope = 'page');
$visitorA->setCustomVariable($id = 2, $name = 'SET WITH EMPTY VALUE PAGE SCOPE', $value = '', $scope = 'page');
$visitorA->setCustomVariable($id = 4, $name = 'Status user', $value = "looking at \"profile page\"", $scope = 'page');
$visitorA->setCustomVariable($id = 3, $name = 'Value will be VERY long and truncated', $value = 'abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----abcdefghijklmnopqrstuvwxyz----');
$this->checkResponse($visitorA->doTrackPageView('Profile page for user *_)%'));
$this->checkResponse($visitorA->doTrackGoal($idGoal, 0));
if ($this->doExtraQuoteTests) {
$visitorA->setCustomVariable($id = 2, $name = 'var1', $value = 'looking at "profile page"',
$scope = 'page');
$visitorA->setCustomVariable($id = 3, $name = 'var2', $value = '\'looking at "\profile page"\'',
$scope = 'page');
$visitorA->setCustomVariable($id = 4, $name = 'var3', $value = '\\looking at "\profile page"\\',
$scope = 'page');
$this->checkResponse($visitorA->doTrackPageView('Concurrent page views'));
}
// -
// Second new visitor on Idsite 1: one page view
$visitorB = $this->getTracker($idSite, $dateTime, $defaultInit = true);
$visitorB->setUrlReferrer('');
$attribution = array(
' CAMPAIGN NAME -%20YEAH! ',
' CAMPAIGN%20KEYWORD - RIGHT... ',
1302306504,
'http://www.example.org/test/really?q=yes'
);
$visitorB->setAttributionInfo(json_encode($attribution));
$visitorB->setResolution($this->width, $this->height);
$visitorB->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6');
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1)->getDatetime());
$visitorB->setCustomVariable($id = 1, $name = 'VisitorType', $value = 'LoggedOut');
$visitorB->setCustomVariable($id = 2, $name = 'Othercustom value which should be truncated abcdefghijklmnopqrstuvwxyz', $value = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz');
$visitorB->setCustomVariable($id = -2, $name = 'not tracked', $value = 'not tracked');
$visitorB->setCustomVariable($id = 6, $name = 'not tracked', $value = 'not tracked');
$visitorB->setCustomVariable($id = 6, $name = array('not tracked'), $value = 'not tracked');
$visitorB->setUrl('http://example.org/homepage');
$this->checkResponse($visitorB->doTrackGoal($idGoal, 1000));
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(1.1)->getDatetime());
$this->checkResponse($visitorB->doTrackPageView('Homepage'));
// DIFFERENT test -
// testing that starting the visit with an outlink works (doesn't trigger errors)
$visitorB->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(2)->getDatetime());
$this->checkResponse($visitorB->doTrackAction('http://test.com', 'link'));
// hack
$this->visitorId = $visitorB->getVisitorId();
}
}