public function track($eventKey, $userId, $attributes = null, $eventTags = null)
    {
        if (!$this->_isValid) {
            $this->_logger->log(Logger::ERROR, 'Datafile has invalid format. Failing "track".');
            return;
        }

        if (!$this->validateInputs(
            [
                self::EVENT_KEY =>$eventKey,
                self::USER_ID => $userId
            ]
        )
        ) {
            return null;
        }

        if (!$this->validateUserInputs($attributes, $eventTags)) {
            return;
        }

        $event = $this->_config->getEvent($eventKey);

        if (is_null($event->getKey())) {
            $this->_logger->log(Logger::INFO, sprintf('Not tracking user "%s" for event "%s".', $userId, $eventKey));
            return;
        }

        $conversionEvent = $this->_eventBuilder
            ->createConversionEvent(
                $this->_config,
                $eventKey,
                $userId,
                $attributes,
                $eventTags
            );
        
        $this->_logger->log(Logger::INFO, sprintf('Tracking event "%s" for user "%s".', $eventKey, $userId));
        $this->_logger->log(
            Logger::DEBUG,
            sprintf(
                'Dispatching conversion event to URL %s with params %s.',
                $conversionEvent->getUrl(),
                json_encode($conversionEvent->getParams())
            )
        );

        try {
            $this->_eventDispatcher->dispatchEvent($conversionEvent);
        } catch (Throwable $exception) {
            $this->_logger->log(
                Logger::ERROR,
                sprintf(
                    'Unable to dispatch conversion event. Error %s',
                    $exception->getMessage()
                )
            );
        } catch (Exception $exception) {
            $this->_logger->log(
                Logger::ERROR,
                sprintf(
                    'Unable to dispatch conversion event. Error %s',
                    $exception->getMessage()
                )
            );
        }

        $this->notificationCenter->sendNotifications(
            NotificationType::TRACK,
            array(
                $eventKey,
                $userId,
                $attributes,
                $eventTags,
                $conversionEvent
            )
        );
    }
public function track($eventKey, $userId, $attributes = null, $eventTags = null)
    {
        if (!$this->_isValid) {
            $this->_logger->log(Logger::ERROR, 'Datafile has invalid format. Failing "track".');
            return;
        }

        if (!$this->validateInputs(
            [
                self::EVENT_KEY =>$eventKey,
                self::USER_ID => $userId
            ]
        )
        ) {
            return null;
        }

        if (!$this->validateUserInputs($attributes, $eventTags)) {
            return;
        }

        $event = $this->_config->getEvent($eventKey);

        if (is_null($event->getKey())) {
            $this->_logger->log(Logger::INFO, sprintf('Not tracking user "%s" for event "%s".', $userId, $eventKey));
            return;
        }

        $conversionEvent = $this->_eventBuilder
            ->createConversionEvent(
                $this->_config,
                $eventKey,
                $userId,
                $attributes,
                $eventTags
            );
        
        $this->_logger->log(Logger::INFO, sprintf('Tracking event "%s" for user "%s".', $eventKey, $userId));
        $this->_logger->log(
            Logger::DEBUG,
            sprintf(
                'Dispatching conversion event to URL %s with params %s.',
                $conversionEvent->getUrl(),
                json_encode($conversionEvent->getParams())
            )
        );

        try {
            $this->_eventDispatcher->dispatchEvent($conversionEvent);
        } catch (Throwable $exception) {
            $this->_logger->log(
                Logger::ERROR,
                sprintf(
                    'Unable to dispatch conversion event. Error %s',
                    $exception->getMessage()
                )
            );
        } catch (Exception $exception) {
            $this->_logger->log(
                Logger::ERROR,
                sprintf(
                    'Unable to dispatch conversion event. Error %s',
                    $exception->getMessage()
                )
            );
        }

        $this->notificationCenter->sendNotifications(
            NotificationType::TRACK,
            array(
                $eventKey,
                $userId,
                $attributes,
                $eventTags,
                $conversionEvent
            )
        );
    }
public function track ( $ eventKey , $ userId , $ attributes = null , $ eventTags = null ) { if ( ! $ this -> _isValid ) { $ this -> _logger -> log ( Logger :: ERROR , 'Datafile has invalid format. Failing "track".' ) ; return ; } if ( ! $ this -> validateInputs ( [ self :: EVENT_KEY => $ eventKey , self :: USER_ID => $ userId ] ) ) { return null ; } if ( ! $ this -> validateUserInputs ( $ attributes , $ eventTags ) ) { return ; } $ event = $ this -> _config -> getEvent ( $ eventKey ) ; if ( is_null ( $ event -> getKey ( ) ) ) { $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'Not tracking user "%s" for event "%s".' , $ userId , $ eventKey ) ) ; return ; } $ conversionEvent = $ this -> _eventBuilder -> createConversionEvent ( $ this -> _config , $ eventKey , $ userId , $ attributes , $ eventTags ) ; $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'Tracking event "%s" for user "%s".' , $ eventKey , $ userId ) ) ; $ this -> _logger -> log ( Logger :: DEBUG , sprintf ( 'Dispatching conversion event to URL %s with params %s.' , $ conversionEvent -> getUrl ( ) , json_encode ( $ conversionEvent -> getParams ( ) ) ) ) ; try { $ this -> _eventDispatcher -> dispatchEvent ( $ conversionEvent ) ; } catch ( Throwable $ exception ) { $ this -> _logger -> log ( Logger :: ERROR , sprintf ( 'Unable to dispatch conversion event. Error %s' , $ exception -> getMessage ( ) ) ) ; } catch ( Exception $ exception ) { $ this -> _logger -> log ( Logger :: ERROR , sprintf ( 'Unable to dispatch conversion event. Error %s' , $ exception -> getMessage ( ) ) ) ; } $ this -> notificationCenter -> sendNotifications ( NotificationType :: TRACK , array ( $ eventKey , $ userId , $ attributes , $ eventTags , $ conversionEvent ) ) ; }
Send conversion event to Optimizely.

@param $eventKey string Event key representing the event which needs to be recorded.
@param $userId string ID for user.
@param $attributes array Attributes of the user.
@param $eventTags array Hash representing metadata associated with the event.
Send conversion event to Optimizely .