public function testForceSet()
 {
     $plugin = new DataSetter(array('test_key' => 'test_value'), true);
     $command = new OperationCommand();
     $command->set('test_key', 'already_stated_value');
     $event = new Event(array('command' => $command));
     $plugin->register($this->client);
     $this->client->getEventDispatcher()->dispatch('command.before_prepare', $event);
     $this->assertSame('test_value', $command->get('test_key'));
 }
 /**
  * @param MeasurementProtocolClient $client
  */
 public function register($client)
 {
     $client->getEventDispatcher()->addListener('command.before_prepare', function ($e) {
         /** @var \Guzzle\Service\Command\OperationCommand $command */
         $command = $e['command'];
         if (!isset($_SERVER['HTTP_USER_AGENT'])) {
             return;
         }
         if ($command->hasKey(HitInterface::FIELD_USER_AGENT)) {
             return;
         }
         $command->set(HitInterface::FIELD_USER_AGENT, $_SERVER['HTTP_USER_AGENT']);
     });
 }
 /**
  * @param MeasurementProtocolClient $client
  */
 public function register($client)
 {
     $data =& $this->data;
     $force =& $this->force;
     $client->getEventDispatcher()->addListener('command.before_prepare', function ($e) use($data, $force) {
         /** @var \Guzzle\Service\Command\OperationCommand $command */
         $command = $e['command'];
         foreach ($data as $key => $val) {
             if (!$command->hasKey($key) || $force) {
                 $command->set($key, $val);
             }
         }
     });
 }
 public function __construct(array $options)
 {
     $options = Collection::fromConfig($options, self::$defaultOptions, self::$requiredOptions);
     $this->client = MeasurementProtocolClient::factory(array('ssl' => $options->get(self::OPT_SSL)));
     $this->registerPlugin(new DataSetter(array(HitInterface::FIELD_VERSION => 1, HitInterface::FIELD_TRACKING_ID => $options->get(self::OPT_TRACKING_ID))));
     $this->registerPlugins($options->get(self::OPT_PLUGINS));
 }
 /**
  * @param MeasurementProtocolClient $client
  */
 public function register($client)
 {
     $cookieName = $this->cookieName;
     $client->getEventDispatcher()->addListener('command.before_prepare', function ($e) use($cookieName) {
         if (!array_key_exists($cookieName, $_COOKIE)) {
             return;
         }
         $parser = new Parser();
         $data = $parser->parse($_COOKIE[$cookieName]);
         /** @var \Guzzle\Service\Command\OperationCommand $command */
         $command = $e['command'];
         if (!$command->hasKey(HitInterface::FIELD_CUSTOMER_ID)) {
             $command->set(HitInterface::FIELD_CUSTOMER_ID, $data->getClientId());
         }
     });
 }
 protected function dispatchCommand(OperationCommand $command)
 {
     $client = MeasurementProtocolClient::factory();
     $plugin = new UserIpOverrider();
     $event = new Event(array('command' => $command));
     $plugin->register($client);
     $client->getEventDispatcher()->dispatch('command.before_prepare', $event);
 }
 /**
  * {@inheritdoc}
  */
 public function trackEvent($category, $action, $label = null, $value = null)
 {
     $this->client->event(array('tid' => $this->getId(), 'cid' => $this->getCustomerId(), 'ec' => $category, 'ea' => $action, 'el' => $label, 'ev' => $value));
 }
 public function __construct()
 {
     $this->client = MeasurementProtocolClient::factory();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('social')->with(array('t' => 'social', 'sa' => 'some_action', 'sn' => 'some_network', 'st' => 'some_target'));
     $this->hit->setAction('some_action')->setNetwork('some_network')->setTarget('some_target')->track();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('pageview')->with(array('t' => 'pageview', 'dh' => 'some_hostname', 'dp' => 'some_path', 'dt' => 'some_title'));
     $this->hit->setDocumentHostname('some_hostname')->setDocumentPath('some_path')->setTitle('some_title')->track();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('event')->with(array('t' => 'event', 'ec' => 'test_category', 'ev' => 'test_value', 'ea' => 'test_action', 'el' => 'test_label', 'cid' => 'test_customer_id', 'tid' => 'test_tracking_id', 'ua' => 'test_user_agent', 'uip' => 'test_user_id', 'v' => 'test_version'));
     $this->hit->setCategory('test_category')->setValue('test_value')->setAction('test_action')->setLabel('test_label')->setCustomerId('test_customer_id')->setTrackingId('test_tracking_id')->setUserAgent('test_user_agent')->setUserIp('test_user_id')->setVersion('test_version')->track();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('timing')->with(array('t' => 'timing', 'utc' => 'some_category', 'utv' => 'some_variable', 'utt' => 'some_time', 'utl' => 'some_label', 'dns' => 'some_dns_load_time', 'pdt' => 'some_page_download_time', 'rrt' => 'some_redirect_time', 'tcp' => 'some_tcp_connect_time', 'srt' => 'some_server_response_time'));
     $this->hit->setCategory('some_category')->setVariable('some_variable')->setTime('some_time')->setLabel('some_label')->setDnsLoadTime('some_dns_load_time')->setPageDownloadTime('some_page_download_time')->setRedirectTime('some_redirect_time')->setTcpConnectTime('some_tcp_connect_time')->setServerResponseTime('some_server_response_time')->track();
 }
 public function testModifyProxyCurlSetting()
 {
     $proxy = 'tcp://localhost:80';
     $client = MeasurementProtocolClient::factory(array('tid' => $this->getTrackingId(), 'curl.options' => array('CURLOPT_PROXY' => $proxy)));
     $this->getResponse('abstract.collect', array('cid' => $this->getCustomerId()), true, $client);
     $requestCurlOptions = $this->history->getLastRequest()->getCurlOptions();
     $this->assertSame($proxy, $requestCurlOptions[CURLOPT_PROXY]);
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('item')->with(array('t' => 'item', 'ti' => 'some_transaction_id', 'cu' => 'some_currency', 'ic' => 'some_item_code', 'in' => 'some_item_name', 'ip' => 'some_item_price', 'iq' => 1, 'iv' => 'some_item_variation'));
     $this->hit->setTransactionId('some_transaction_id')->setCurrency('some_currency')->setItemCode('some_item_code')->setItemName('some_item_name')->setItemPrice('some_item_price')->setItemQuantity('1')->setItemVariation('some_item_variation')->track();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('screenview')->with(array('t' => 'screenview', 'an' => 'some_app_name', 'av' => 'some_app_version', 'aid' => 'some_app_id', 'aiid' => 'some_app_installer_id', 'cd' => 'some_content_description'));
     $this->hit->setAppName('some_app_name')->setAppVersion('some_app_version')->setAppId('some_app_id')->setAppInstallerId('some_app_installer_id')->setContentDescription('some_content_description')->track();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('transaction')->with(array('t' => 'transaction', 'ti' => 'some_id', 'ta' => 'some_affiliation', 'tr' => 'some_revenue', 'ts' => 'some_shipping', 'tt' => 'some_tax', 'cu' => 'some_currency'));
     $this->hit->setId('some_id')->setAffiliation('some_affiliation')->setRevenue('some_revenue')->setShipping('some_shipping')->setTax('some_tax')->setCurrency('some_currency')->track();
 }
 public function testTrack()
 {
     $this->clientMock->expects($this->once())->method('exception')->with(array('t' => 'exception', 'exd' => 'test_exception_description', 'exf' => true));
     $this->hit->setExceptionDescription('test_exception_description')->setExceptionIsFatal(true)->track();
 }