|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright 2016-2018, Optimizely |
| 3 | + * Copyright 2016-2019, 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. |
@@ -192,43 +192,6 @@ private function validateUserInputs($attributes, $eventTags = null) |
192 | 192 | return true; |
193 | 193 | } |
194 | 194 |
|
195 | | - /** |
196 | | - * Get the experiments that we should be tracking for the given event. A valid experiment |
197 | | - * is one that is in "Running" state and into which the user has been bucketed. |
198 | | - * |
199 | | - * @param $event string Event key representing the event which needs to be recorded. |
200 | | - * @param $user string ID for user. |
201 | | - * @param $attributes array Attributes of the user. |
202 | | - * |
203 | | - * @return Array Of objects where each object contains the ID of the experiment to track and the ID of the variation the user is bucketed into. |
204 | | - */ |
205 | | - private function getValidExperimentsForEvent($event, $userId, $attributes = null) |
206 | | - { |
207 | | - $validExperiments = []; |
208 | | - foreach ($event->getExperimentIds() as $experimentId) { |
209 | | - $experiment = $this->_config->getExperimentFromId($experimentId); |
210 | | - $experimentKey = $experiment->getKey(); |
211 | | - $variationKey = $this->getVariation($experimentKey, $userId, $attributes); |
212 | | - |
213 | | - if (is_null($variationKey)) { |
214 | | - $this->_logger->log( |
215 | | - Logger::INFO, |
216 | | - sprintf( |
217 | | - 'Not tracking user "%s" for experiment "%s".', |
218 | | - $userId, |
219 | | - $experimentKey |
220 | | - ) |
221 | | - ); |
222 | | - continue; |
223 | | - } |
224 | | - |
225 | | - $variation = $this->_config->getVariationFromKey($experimentKey, $variationKey); |
226 | | - $validExperiments[$experimentId] = $variation->getId(); |
227 | | - } |
228 | | - |
229 | | - return $validExperiments; |
230 | | - } |
231 | | - |
232 | 195 | /** |
233 | 196 | * @param string Experiment key |
234 | 197 | * @param string Variation key |
@@ -350,68 +313,59 @@ public function track($eventKey, $userId, $attributes = null, $eventTags = null) |
350 | 313 | $event = $this->_config->getEvent($eventKey); |
351 | 314 |
|
352 | 315 | if (is_null($event->getKey())) { |
353 | | - $this->_logger->log(Logger::ERROR, sprintf('Not tracking user "%s" for event "%s".', $userId, $eventKey)); |
| 316 | + $this->_logger->log(Logger::INFO, sprintf('Not tracking user "%s" for event "%s".', $userId, $eventKey)); |
354 | 317 | return; |
355 | 318 | } |
356 | 319 |
|
357 | | - // Filter out experiments that are not running or when user(s) do not meet conditions. |
358 | | - $experimentVariationMap = $this->getValidExperimentsForEvent($event, $userId, $attributes); |
359 | | - if (!empty($experimentVariationMap)) { |
360 | | - $conversionEvent = $this->_eventBuilder |
361 | | - ->createConversionEvent( |
362 | | - $this->_config, |
363 | | - $eventKey, |
364 | | - $experimentVariationMap, |
365 | | - $userId, |
366 | | - $attributes, |
367 | | - $eventTags |
368 | | - ); |
369 | | - $this->_logger->log(Logger::INFO, sprintf('Tracking event "%s" for user "%s".', $eventKey, $userId)); |
370 | | - $this->_logger->log( |
371 | | - Logger::DEBUG, |
372 | | - sprintf( |
373 | | - 'Dispatching conversion event to URL %s with params %s.', |
374 | | - $conversionEvent->getUrl(), |
375 | | - json_encode($conversionEvent->getParams()) |
376 | | - ) |
| 320 | + $conversionEvent = $this->_eventBuilder |
| 321 | + ->createConversionEvent( |
| 322 | + $this->_config, |
| 323 | + $eventKey, |
| 324 | + $userId, |
| 325 | + $attributes, |
| 326 | + $eventTags |
377 | 327 | ); |
| 328 | + |
| 329 | + $this->_logger->log(Logger::INFO, sprintf('Tracking event "%s" for user "%s".', $eventKey, $userId)); |
| 330 | + $this->_logger->log( |
| 331 | + Logger::DEBUG, |
| 332 | + sprintf( |
| 333 | + 'Dispatching conversion event to URL %s with params %s.', |
| 334 | + $conversionEvent->getUrl(), |
| 335 | + json_encode($conversionEvent->getParams()) |
| 336 | + ) |
| 337 | + ); |
378 | 338 |
|
379 | | - try { |
380 | | - $this->_eventDispatcher->dispatchEvent($conversionEvent); |
381 | | - } catch (Throwable $exception) { |
382 | | - $this->_logger->log( |
383 | | - Logger::ERROR, |
384 | | - sprintf( |
385 | | - 'Unable to dispatch conversion event. Error %s', |
386 | | - $exception->getMessage() |
387 | | - ) |
388 | | - ); |
389 | | - } catch (Exception $exception) { |
390 | | - $this->_logger->log( |
391 | | - Logger::ERROR, |
392 | | - sprintf( |
393 | | - 'Unable to dispatch conversion event. Error %s', |
394 | | - $exception->getMessage() |
395 | | - ) |
396 | | - ); |
397 | | - } |
398 | | - |
399 | | - $this->notificationCenter->sendNotifications( |
400 | | - NotificationType::TRACK, |
401 | | - array( |
402 | | - $eventKey, |
403 | | - $userId, |
404 | | - $attributes, |
405 | | - $eventTags, |
406 | | - $conversionEvent |
| 339 | + try { |
| 340 | + $this->_eventDispatcher->dispatchEvent($conversionEvent); |
| 341 | + } catch (Throwable $exception) { |
| 342 | + $this->_logger->log( |
| 343 | + Logger::ERROR, |
| 344 | + sprintf( |
| 345 | + 'Unable to dispatch conversion event. Error %s', |
| 346 | + $exception->getMessage() |
407 | 347 | ) |
408 | 348 | ); |
409 | | - } else { |
| 349 | + } catch (Exception $exception) { |
410 | 350 | $this->_logger->log( |
411 | | - Logger::INFO, |
412 | | - sprintf('There are no valid experiments for event "%s" to track.', $eventKey) |
| 351 | + Logger::ERROR, |
| 352 | + sprintf( |
| 353 | + 'Unable to dispatch conversion event. Error %s', |
| 354 | + $exception->getMessage() |
| 355 | + ) |
413 | 356 | ); |
414 | 357 | } |
| 358 | + |
| 359 | + $this->notificationCenter->sendNotifications( |
| 360 | + NotificationType::TRACK, |
| 361 | + array( |
| 362 | + $eventKey, |
| 363 | + $userId, |
| 364 | + $attributes, |
| 365 | + $eventTags, |
| 366 | + $conversionEvent |
| 367 | + ) |
| 368 | + ); |
415 | 369 | } |
416 | 370 |
|
417 | 371 | /** |
|
0 commit comments