|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright 2016, Optimizely |
| 3 | + * Copyright 2016-2017, Optimizely |
4 | 4 | * |
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | 6 | * you may not use this file except in compliance with the License. |
|
22 | 22 | use Optimizely\Entity\Experiment; |
23 | 23 | use Optimizely\Event\LogEvent; |
24 | 24 | use Optimizely\ProjectConfig; |
| 25 | +use Optimizely\Utils\EventTagUtils; |
25 | 26 |
|
26 | 27 | class EventBuilder |
27 | 28 | { |
@@ -153,20 +154,34 @@ private function setImpressionParams(Experiment $experiment, $variationId) |
153 | 154 | * @param $eventKey string Key representing the event. |
154 | 155 | * @param $experiments array Experiments for which conversion event needs to be recorded. |
155 | 156 | * @param $userId string ID of user. |
156 | | - * @param $eventValue integer Value associated with the event. |
| 157 | + * @param $eventTags array Hash representing metadata associated with the event. |
157 | 158 | */ |
158 | | - private function setConversionParams($config, $eventKey, $experiments, $userId, $eventValue) |
| 159 | + private function setConversionParams($config, $eventKey, $experiments, $userId, $eventTags) |
159 | 160 | { |
160 | 161 | $this->_eventParams[EVENT_FEATURES] = []; |
161 | 162 | $this->_eventParams[EVENT_METRICS] = []; |
162 | 163 |
|
163 | | - if (!is_null($eventValue)) { |
164 | | - $this->_eventParams[EVENT_METRICS] = [ |
165 | | - [ |
166 | | - 'name' => 'revenue', |
167 | | - 'value' => $eventValue |
168 | | - ] |
169 | | - ]; |
| 164 | + if (!is_null($eventTags)) { |
| 165 | + forEach ($eventTags as $eventTagId => $eventTagValue) { |
| 166 | + if (is_null($eventTagValue)) { |
| 167 | + continue; |
| 168 | + } |
| 169 | + $eventFeature = array( |
| 170 | + 'id' => $eventTagId, |
| 171 | + 'type' => 'custom', |
| 172 | + 'value' => $eventTagValue, |
| 173 | + 'shouldIndex' => false, |
| 174 | + ); |
| 175 | + array_push($this->_eventParams[EVENT_FEATURES], $eventFeature); |
| 176 | + } |
| 177 | + $eventValue = EventTagUtils::getRevenueValue($eventTags); |
| 178 | + if ($eventValue) { |
| 179 | + $eventMetric = array( |
| 180 | + 'name' => EventTagUtils::REVENUE_EVENT_METRIC_NAME, |
| 181 | + 'value' => $eventValue, |
| 182 | + ); |
| 183 | + array_push($this->_eventParams[EVENT_METRICS], $eventMetric); |
| 184 | + } |
170 | 185 | } |
171 | 186 |
|
172 | 187 | $eventEntity = $config->getEvent($eventKey); |
@@ -218,15 +233,15 @@ public function createImpressionEvent($config, Experiment $experiment, $variatio |
218 | 233 | * @param $experiments array Experiments for which conversion event needs to be recorded. |
219 | 234 | * @param $userId string ID of user. |
220 | 235 | * @param $attributes array Attributes of the user. |
221 | | - * @param $eventValue integer Value associated with the event. |
| 236 | + * @param $eventTags array Hash representing metadata associated with the event. |
222 | 237 | * |
223 | 238 | * @return LogEvent Event object to be sent to dispatcher. |
224 | 239 | */ |
225 | | - public function createConversionEvent($config, $eventKey, $experiments, $userId, $attributes, $eventValue) |
| 240 | + public function createConversionEvent($config, $eventKey, $experiments, $userId, $attributes, $eventTags) |
226 | 241 | { |
227 | 242 | $this->resetParams(); |
228 | 243 | $this->setCommonParams($config, $userId, $attributes); |
229 | | - $this->setConversionParams($config, $eventKey, $experiments, $userId, $eventValue); |
| 244 | + $this->setConversionParams($config, $eventKey, $experiments, $userId, $eventTags); |
230 | 245 |
|
231 | 246 | return new LogEvent(self::$CONVERSION_ENDPOINT, $this->getParams(), self::$HTTP_VERB, self::$HTTP_HEADERS); |
232 | 247 | } |
|
0 commit comments