1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 10 October 2016 |
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
6
|
|
|
*/ |
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
8
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* An Optimizely web snippet configuration. |
13
|
|
|
*/ |
14
|
|
|
class WebSnippet |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Enables the option to force yourself into a specific Variation on any page |
18
|
|
|
* @var boolean |
19
|
|
|
*/ |
20
|
|
|
private $enableForceVariation; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Set to true to remove paused and draft experiments from the snippet |
24
|
|
|
* @var boolean |
25
|
|
|
*/ |
26
|
|
|
private $excludeDisabledExperiments; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set to true to mask descriptive names |
30
|
|
|
* @var boolean |
31
|
|
|
*/ |
32
|
|
|
private $excludeNames; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Set to true to include jQuery in your snippet. |
36
|
|
|
* @var boolean |
37
|
|
|
*/ |
38
|
|
|
private $includeJquery; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Set to true to change the last octet of IP addresses to 0 prior to logging |
42
|
|
|
* @var boolean |
43
|
|
|
*/ |
44
|
|
|
private $ipAnonymization; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* A regular expression (max 1500 characters) matching ip addresses for |
48
|
|
|
* filtering out visitors. Matching visitors will still see the experiments, |
49
|
|
|
* but they won't be counted in results. |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $ipFilter; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The prefered jQuery library version you would like to use with your snippet. |
56
|
|
|
* If you do not want to include jQuery, set include_jquery to false. Can be |
57
|
|
|
* 'jquery-1.11.3-trim', 'jquery-1.11.3-full', 'jquery-1.6.4-trim', 'jquery-1.6.4-full' |
58
|
|
|
* or 'none'. |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private $library; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The javascript code which runs before Optimizely on all pages, regardless |
65
|
|
|
* of whether or not there is a running experiment. |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $projectJavascript; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The current revision number of the project snippet |
72
|
|
|
* @var integer |
73
|
|
|
*/ |
74
|
|
|
private $codeRevision; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* The current size in bytes of the project snippet |
78
|
|
|
* @var integer |
79
|
|
|
*/ |
80
|
|
|
private $jsFileSize; |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Constructor. |
85
|
|
|
*/ |
86
|
7 |
|
public function __construct($options = array()) |
87
|
|
|
{ |
88
|
7 |
|
foreach ($options as $name=>$value) { |
89
|
|
|
switch ($name) { |
90
|
6 |
|
case 'enable_force_variation': $this->setEnableForceVariation($value); break; |
91
|
6 |
|
case 'exclude_disabled_experiments': $this->setExcludeDisabledExperiments($value); break; |
92
|
6 |
|
case 'exclude_names': $this->setExcludeNames($value); break; |
93
|
6 |
|
case 'include_jquery': $this->setIncludeJquery($value); break; |
94
|
6 |
|
case 'ip_anonymization': $this->setIpAnonymization($value); break; |
95
|
6 |
|
case 'ip_filter': $this->setIpFilter($value); break; |
96
|
6 |
|
case 'library': $this->setLibrary($value); break; |
97
|
6 |
|
case 'project_javascript': $this->setProjectJavascript($value); break; |
98
|
6 |
|
case 'code_revision': $this->setCodeRevision($value); break; |
99
|
6 |
|
case 'js_file_size': $this->setJsFileSize($value); break; |
100
|
|
|
default: |
101
|
6 |
|
throw new Exception('Unknown option found in WebSnippet entity: ' . $name); |
102
|
|
|
} |
103
|
|
|
} |
104
|
7 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns this object as array. |
108
|
|
|
*/ |
109
|
3 |
|
public function toArray() |
110
|
|
|
{ |
111
|
|
|
$options = array( |
112
|
3 |
|
'enable_force_variation' => $this->enableForceVariation, |
113
|
3 |
|
'exclude_disabled_experiments' => $this->excludeDisabledExperiments, |
114
|
3 |
|
'exclude_names' => $this->excludeNames, |
115
|
3 |
|
'include_jquery' => $this->includeJquery, |
116
|
3 |
|
'ip_anonymization' => $this->ipAnonymization, |
117
|
3 |
|
'ip_filter' => $this->ipFilter, |
118
|
3 |
|
'library' => $this->library, |
119
|
3 |
|
'project_javascript' => $this->projectJavascript, |
120
|
3 |
|
'code_revision' => $this->codeRevision, |
121
|
3 |
|
'js_file_size' => $this->jsFileSize |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
// Remove options with empty values |
125
|
3 |
|
$cleanedOptions = array(); |
126
|
3 |
|
foreach ($options as $name=>$value) { |
127
|
3 |
|
if ($value!==null) |
128
|
3 |
|
$cleanedOptions[$name] = $value; |
129
|
|
|
} |
130
|
|
|
|
131
|
3 |
|
return $cleanedOptions; |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
public function getEnableForceVariation() |
135
|
|
|
{ |
136
|
1 |
|
return $this->enableForceVariation; |
137
|
|
|
} |
138
|
|
|
|
139
|
7 |
|
public function setEnableForceVariation($enableForceVariation) |
140
|
|
|
{ |
141
|
7 |
|
$this->enableForceVariation = $enableForceVariation; |
142
|
7 |
|
} |
143
|
|
|
|
144
|
2 |
|
public function getExcludeDisabledExperiments() |
145
|
|
|
{ |
146
|
2 |
|
return $this->excludeDisabledExperiments; |
147
|
|
|
} |
148
|
|
|
|
149
|
7 |
|
public function setExcludeDisabledExperiments($excludeDisabledExperiments) |
150
|
|
|
{ |
151
|
7 |
|
$this->excludeDisabledExperiments = $excludeDisabledExperiments; |
152
|
7 |
|
} |
153
|
|
|
|
154
|
1 |
|
public function getExcludeNames() |
155
|
|
|
{ |
156
|
1 |
|
return $this->excludeNames; |
157
|
|
|
} |
158
|
|
|
|
159
|
7 |
|
public function setExcludeNames($excludeNames) |
160
|
|
|
{ |
161
|
7 |
|
$this->excludeNames = $excludeNames; |
162
|
7 |
|
} |
163
|
|
|
|
164
|
1 |
|
public function getIncludeJquery() |
165
|
|
|
{ |
166
|
1 |
|
return $this->includeJquery; |
167
|
|
|
} |
168
|
|
|
|
169
|
7 |
|
public function setIncludeJquery($includeJquery) |
170
|
|
|
{ |
171
|
7 |
|
$this->includeJquery = $includeJquery; |
172
|
7 |
|
} |
173
|
|
|
|
174
|
1 |
|
public function getIpAnonymization() |
175
|
|
|
{ |
176
|
1 |
|
return $this->ipAnonymization; |
177
|
|
|
} |
178
|
|
|
|
179
|
7 |
|
public function setIpAnonymization($ipAnonymization) |
180
|
|
|
{ |
181
|
7 |
|
$this->ipAnonymization = $ipAnonymization; |
182
|
7 |
|
} |
183
|
|
|
|
184
|
2 |
|
public function getIpFilter() |
185
|
|
|
{ |
186
|
2 |
|
return $this->ipFilter; |
187
|
|
|
} |
188
|
|
|
|
189
|
7 |
|
public function setIpFilter($ipFilter) |
190
|
|
|
{ |
191
|
7 |
|
$this->ipFilter = $ipFilter; |
192
|
7 |
|
} |
193
|
|
|
|
194
|
1 |
|
public function getLibrary() |
195
|
|
|
{ |
196
|
1 |
|
return $this->library; |
197
|
|
|
} |
198
|
|
|
|
199
|
7 |
|
public function setLibrary($library) |
200
|
|
|
{ |
201
|
7 |
|
$this->library = $library; |
202
|
7 |
|
} |
203
|
|
|
|
204
|
1 |
|
public function getProjectJavascript() |
205
|
|
|
{ |
206
|
1 |
|
return $this->projectJavascript; |
207
|
|
|
} |
208
|
|
|
|
209
|
7 |
|
public function setProjectJavascript($projectJavascript) |
210
|
|
|
{ |
211
|
7 |
|
$this->projectJavascript = $projectJavascript; |
212
|
7 |
|
} |
213
|
|
|
|
214
|
1 |
|
public function getCodeRevision() |
215
|
|
|
{ |
216
|
1 |
|
return $this->codeRevision; |
217
|
|
|
} |
218
|
|
|
|
219
|
7 |
|
public function setCodeRevision($codeRevision) |
220
|
|
|
{ |
221
|
7 |
|
$this->codeRevision = $codeRevision; |
222
|
7 |
|
} |
223
|
|
|
|
224
|
1 |
|
public function getJsFileSize() |
225
|
|
|
{ |
226
|
1 |
|
return $this->jsFileSize; |
227
|
|
|
} |
228
|
|
|
|
229
|
7 |
|
public function setJsFileSize($jsFileSize) |
230
|
|
|
{ |
231
|
7 |
|
$this->jsFileSize = $jsFileSize; |
232
|
7 |
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
|
237
|
|
|
|
238
|
|
|
|
239
|
|
|
|
240
|
|
|
|
241
|
|
|
|
242
|
|
|
|