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 |
|
case 'results': { |
|
|
|
|
121
|
3 |
|
$results = []; |
122
|
3 |
|
foreach ($value as $key=>$result) { |
123
|
3 |
|
$results[$key] = new VariantResults($result); |
124
|
|
|
} |
125
|
3 |
|
$this->setResults($results); break; |
126
|
|
|
} |
127
|
|
|
case 'name': $this->setName($value); break; |
|
|
|
|
128
|
|
|
case 'scope': $this->setScope($value); break; |
|
|
|
|
129
|
|
|
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
|
3 |
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Returns this object as array. |
138
|
|
|
*/ |
139
|
1 |
|
public function toArray() |
140
|
|
|
{ |
141
|
|
|
$options = array( |
142
|
1 |
|
'aggregator' => $this->getAggregator(), |
143
|
1 |
|
'event_id' => $this->getEventId(), |
144
|
1 |
|
'event_name' => $this->getEventName(), |
145
|
1 |
|
'field' => $this->getField(), |
146
|
1 |
|
'measure' => $this->getMeasure(), |
147
|
1 |
|
'metric_id' => $this->getMetricId(), |
148
|
1 |
|
'priority' => $this->getPriority(), |
149
|
1 |
|
'unit' => $this->getUnit(), |
150
|
1 |
|
'name' => $this->getName(), |
151
|
1 |
|
'scope' => $this->getScope(), |
152
|
1 |
|
'winning_direction' => $this->getWinningDirection(), |
153
|
|
|
'results' => array(), |
154
|
|
|
); |
155
|
|
|
|
156
|
1 |
|
foreach ($this->getResults() as $key=>$result) { |
157
|
1 |
|
$options['results'][$key] = $result->toArray(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// Remove options with empty values |
161
|
1 |
|
$cleanedOptions = array(); |
162
|
1 |
|
foreach ($options as $name=>$value) { |
163
|
1 |
|
if ($value!==null) |
164
|
1 |
|
$cleanedOptions[$name] = $value; |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
return $cleanedOptions; |
168
|
|
|
} |
169
|
|
|
|
170
|
1 |
|
public function getAggregator() |
171
|
|
|
{ |
172
|
1 |
|
return $this->aggregator; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function setAggregator($aggregator) |
176
|
|
|
{ |
177
|
|
|
$this->aggregator = $aggregator; |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
public function getEventId() |
181
|
|
|
{ |
182
|
1 |
|
return $this->eventId; |
183
|
|
|
} |
184
|
|
|
|
185
|
3 |
|
public function setEventId($eventId) |
186
|
|
|
{ |
187
|
3 |
|
$this->eventId = $eventId; |
188
|
3 |
|
} |
189
|
|
|
|
190
|
1 |
|
public function getEventName() |
191
|
|
|
{ |
192
|
1 |
|
return $this->eventName; |
193
|
|
|
} |
194
|
|
|
|
195
|
3 |
|
public function setEventName($eventName) |
196
|
|
|
{ |
197
|
3 |
|
$this->eventName = $eventName; |
198
|
3 |
|
} |
199
|
|
|
|
200
|
1 |
|
public function getField() |
201
|
|
|
{ |
202
|
1 |
|
return $this->field; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function setField($field) |
206
|
|
|
{ |
207
|
|
|
$this->field = $field; |
208
|
|
|
} |
209
|
|
|
|
210
|
1 |
|
public function getMeasure() |
211
|
|
|
{ |
212
|
1 |
|
return $this->measure; |
213
|
|
|
} |
214
|
|
|
|
215
|
3 |
|
public function setMeasure($measure) |
216
|
|
|
{ |
217
|
3 |
|
$this->measure = $measure; |
218
|
3 |
|
} |
219
|
|
|
|
220
|
1 |
|
public function getMetricId() |
221
|
|
|
{ |
222
|
1 |
|
return $this->metricId; |
223
|
|
|
} |
224
|
|
|
|
225
|
3 |
|
public function setMetricId($metricId) |
226
|
|
|
{ |
227
|
3 |
|
$this->metricId = $metricId; |
228
|
3 |
|
} |
229
|
|
|
|
230
|
1 |
|
public function getPriority() |
231
|
|
|
{ |
232
|
1 |
|
return $this->priority; |
233
|
|
|
} |
234
|
|
|
|
235
|
3 |
|
public function setPriority($priority) |
236
|
|
|
{ |
237
|
3 |
|
$this->priority = $priority; |
238
|
3 |
|
} |
239
|
|
|
|
240
|
1 |
|
public function getUnit() |
241
|
|
|
{ |
242
|
1 |
|
return $this->unit; |
243
|
|
|
} |
244
|
|
|
|
245
|
3 |
|
public function setUnit($unit) |
246
|
|
|
{ |
247
|
3 |
|
$this->unit = $unit; |
248
|
3 |
|
} |
249
|
|
|
|
250
|
1 |
|
public function getResults() |
251
|
|
|
{ |
252
|
1 |
|
return $this->results; |
253
|
|
|
} |
254
|
|
|
|
255
|
3 |
|
public function setResults($results) |
256
|
|
|
{ |
257
|
3 |
|
$this->results = $results; |
258
|
3 |
|
} |
259
|
|
|
|
260
|
1 |
|
public function getName() |
261
|
|
|
{ |
262
|
1 |
|
return $this->name; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function setName($name) |
266
|
|
|
{ |
267
|
|
|
$this->name = $name; |
268
|
|
|
} |
269
|
|
|
|
270
|
1 |
|
public function getScope() |
271
|
|
|
{ |
272
|
1 |
|
return $this->scope; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function setScope($scope) |
276
|
|
|
{ |
277
|
|
|
$this->scope = $scope; |
278
|
|
|
} |
279
|
|
|
|
280
|
1 |
|
public function getWinningDirection() |
281
|
|
|
{ |
282
|
1 |
|
return $this->winningDirection; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function setWinningDirection($winningDirection) |
286
|
|
|
{ |
287
|
|
|
$this->winningDirection = $winningDirection; |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
|
294
|
|
|
|
295
|
|
|
|
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
|
300
|
|
|
|
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.