1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 12 October 2016 |
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
6
|
|
|
*/ |
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
8
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
10
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\VariantResults; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Optimizely experiment metric results. |
14
|
|
|
*/ |
15
|
|
|
class ExperimentMetricResults |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* The aggregation function for the numerator of the metric. 'unique' measures |
19
|
|
|
* the number of unique visitors/sessions that include the specified Event. |
20
|
|
|
* 'count' measures the total number of occurrences of Event for the scope |
21
|
|
|
* (visitor/session). 'sum' is the sum of the 'field' value. 'exit' measures |
22
|
|
|
* the ratio of sessions with last activation occurring on the target page to |
23
|
|
|
* the sessions that activated the target page at least once during the session. |
24
|
|
|
* 'bounce' measures the ratio of sessions that with first and last activation |
25
|
|
|
* occurring on the target page to the sessions with first activation on the |
26
|
|
|
* target page. For both 'exit' and 'bounce', the eventId must be the ID of a Page. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $aggregator; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $eventId; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $eventName; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @var type |
47
|
|
|
*/ |
48
|
|
|
private $field; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Conversions indicate the total number of visitors or sessions where the |
52
|
|
|
* event happened. Impressions indicate the total number of times the event |
53
|
|
|
* happened (possibly multiple per visitor or session). Revenue indicates |
54
|
|
|
* the sum of all revenue sent from all events in the Experiment. |
55
|
|
|
* Can be 'conversions', 'impressions' or 'revenue'. |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
private $measure; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
private $metricId; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
* @var integer |
69
|
|
|
*/ |
70
|
|
|
private $priority; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Can be 'session', 'visitor' or 'event' |
74
|
|
|
* @var string |
75
|
|
|
*/ |
76
|
|
|
private $unit; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $name; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* A map of results for each variation in the Experiment keyed by variation ID. |
86
|
|
|
* For Personalization Campaigns, the special variant 'baseline' represents |
87
|
|
|
* visitors that have been held back from any change in experience for the Experiment |
88
|
|
|
* |
89
|
|
|
* @var object[VariantResults] |
90
|
|
|
*/ |
91
|
|
|
private $results; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* |
95
|
|
|
* @var string |
96
|
|
|
*/ |
97
|
|
|
private $scope; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
* @var type |
102
|
|
|
*/ |
103
|
|
|
private $winningDirection; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Constructor. |
107
|
|
|
*/ |
108
|
3 |
|
public function __construct($options = array()) |
109
|
|
|
{ |
110
|
3 |
|
foreach ($options as $name=>$value) { |
111
|
|
|
switch ($name) { |
112
|
3 |
|
case 'aggregator': $this->setAggregator($value); break; |
|
|
|
|
113
|
3 |
|
case 'event_id': $this->setEventId($value); break; |
|
|
|
|
114
|
3 |
|
case 'event_name': $this->setEventName($value); break; |
|
|
|
|
115
|
3 |
|
case 'field': $this->setField($value); break; |
|
|
|
|
116
|
3 |
|
case 'measure': $this->setMeasure($value); break; |
|
|
|
|
117
|
3 |
|
case 'metric_id': $this->setMetricId($value); break; |
|
|
|
|
118
|
3 |
|
case 'priority': $this->setPriority($value); break; |
|
|
|
|
119
|
3 |
|
case 'unit': $this->setUnit($value); break; |
|
|
|
|
120
|
3 |
View Code Duplication |
case 'results': { |
|
|
|
|
121
|
|
|
$results = []; |
122
|
|
|
foreach ($value as $result) { |
123
|
|
|
$results[] = new VariantResults($result); |
124
|
|
|
} |
125
|
|
|
$this->setResults($results); break; |
126
|
|
|
} |
127
|
3 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
128
|
3 |
|
case 'scope': $this->setScope($value); break; |
|
|
|
|
129
|
3 |
|
case 'winning_direction': $this->setWinningDirection($value); break; |
|
|
|
|
130
|
|
|
default: |
131
|
3 |
|
throw new Exception('Unknown option found in the ExperimentMetricResults entity: ' . $name); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns this object as array. |
138
|
|
|
*/ |
139
|
|
|
public function toArray() |
140
|
|
|
{ |
141
|
|
|
return array( |
142
|
|
|
'aggregator' => $this->getAggregator(), |
143
|
|
|
'event_id' => $this->getEventId(), |
144
|
|
|
'event_name' => $this->getEventName(), |
145
|
|
|
'field' => $this->getField(), |
146
|
|
|
'measure' => $this->getMeasure(), |
147
|
|
|
'metric_id' => $this->getMetricId(), |
148
|
|
|
'priority' => $this->getPriority(), |
149
|
|
|
'unit' => $this->getUnit(), |
150
|
|
|
'results' => $this->getResults()->toArray(), |
151
|
|
|
'name' => $this->getName(), |
152
|
|
|
'scope' => $this->getScope(), |
153
|
|
|
'winning_direction' => $this->getWinningDirection(), |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getAggregator() |
158
|
|
|
{ |
159
|
|
|
return $this->aggregator; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setAggregator($aggregator) |
163
|
|
|
{ |
164
|
|
|
$this->aggregator = $aggregator; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getEventId() |
168
|
|
|
{ |
169
|
|
|
return $this->eventId; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function setEventId($eventId) |
173
|
|
|
{ |
174
|
|
|
$this->eventId = $eventId; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getEventName() |
178
|
|
|
{ |
179
|
|
|
return $this->eventName; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function setEventName($eventName) |
183
|
|
|
{ |
184
|
|
|
$this->eventName = $eventName; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function getField() |
188
|
|
|
{ |
189
|
|
|
return $this->field; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function setField($field) |
193
|
|
|
{ |
194
|
|
|
$this->field = $field; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
public function getMeasure() |
198
|
|
|
{ |
199
|
|
|
return $this->measure; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function setMeasure($measure) |
203
|
|
|
{ |
204
|
|
|
$this->measure = $measure; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function getMetricId() |
208
|
|
|
{ |
209
|
|
|
return $this->metricId; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function setMetricId($metricId) |
213
|
|
|
{ |
214
|
|
|
$this->metricId = $metricId; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function getPriority() |
218
|
|
|
{ |
219
|
|
|
return $this->priority; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function setPriority($priority) |
223
|
|
|
{ |
224
|
|
|
$this->priority = $priority; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function getUnit() |
228
|
|
|
{ |
229
|
|
|
return $this->unit; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function setUnit($unit) |
233
|
|
|
{ |
234
|
|
|
$this->unit = $unit; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function getResults() |
238
|
|
|
{ |
239
|
|
|
return $this->results; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function setResults($results) |
243
|
|
|
{ |
244
|
|
|
$this->results = $results; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function getName() |
248
|
|
|
{ |
249
|
|
|
return $this->name; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
public function setName($name) |
253
|
|
|
{ |
254
|
|
|
$this->name = $name; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
public function getScope() |
258
|
|
|
{ |
259
|
|
|
return $this->scope; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
public function setScope($scope) |
263
|
|
|
{ |
264
|
|
|
$this->scope = $scope; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
public function getWinningDirection() |
268
|
|
|
{ |
269
|
|
|
return $this->winningDirection; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function setWinningDirection($winningDirection) |
273
|
|
|
{ |
274
|
|
|
$this->winningDirection = $winningDirection; |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
|
280
|
|
|
|
281
|
|
|
|
282
|
|
|
|
283
|
|
|
|
284
|
|
|
|
285
|
|
|
|
286
|
|
|
|
287
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.