예제 #1
0
 public function testAddCustomVariablesWithSameId()
 {
     $tracker = new Tracker(123);
     $variable1 = new CustomVariable(1, 'var1', 'value1');
     $variable2 = new CustomVariable(1, 'var2', 'value2');
     $tracker->addCustomVariable($variable1);
     $this->setExpectedException('SlmGoogleAnalytics\\Exception\\InvalidArgumentException');
     $tracker->addCustomVariable($variable2);
 }
예제 #2
0
 public function testCannotAddTransactionsWithSameId()
 {
     $this->setExpectedException('SlmGoogleAnalytics\\Exception\\InvalidArgumentException');
     $tracker = new Tracker(123);
     $transaction1 = new Transaction(456, 12.5);
     $transaction2 = new Transaction(456, 12.5);
     $tracker->addTransaction($transaction1);
     $tracker->addTransaction($transaction2);
 }
예제 #3
0
 public function testCanAddMultipleEventsToTracker()
 {
     $tracker = new Tracker(123);
     $event1 = new Event('Category', 'Action');
     $event2 = new Event('Category', 'Action');
     $tracker->addEvent($event1);
     $tracker->addEvent($event2);
     $events = count($tracker->getEvents());
     $this->assertEquals(2, $events);
 }
예제 #4
0
 public function testHelperRendersItemWithOptionalValuesEmpty()
 {
     $transaction = new Transaction(123, 12.55);
     $item = new Item(456, 9.66, 1);
     $transaction->addItem($item);
     $this->tracker->addTransaction($transaction);
     $expected = '_gaq.push(["_addItem",123,456,null,null,9.66,1])';
     $actual = $this->script->getCode();
     $this->assertContains($expected, $actual);
 }
예제 #5
0
 public function testHelperRendersTransactionWithMultipleItems()
 {
     $transaction = new Transaction(123, 12.55);
     $item1 = new Item(456, 9.66, 1, 'Product1', 'Category1');
     $item2 = new Item(789, 15.33, 2, 'Product2', 'Category2');
     $transaction->addItem($item1);
     $transaction->addItem($item2);
     $this->tracker->addTransaction($transaction);
     $expected = 'ga("ecommerce:addItem",{"id":123,"name":"Product1","sku":456,"category":"Category1","price":9.66,"quantity":1});';
     $actual = $this->script->getCode();
     $this->assertContains($expected, $actual);
     $expected = 'ga("ecommerce:addItem",{"id":123,"name":"Product2","sku":789,"category":"Category2","price":15.33,"quantity":2});';
     $this->assertContains($expected, $actual);
 }
예제 #6
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $gaConfig = $config['google_analytics'];
     $tracker = new Tracker($gaConfig['id']);
     if (isset($gaConfig['domain_name'])) {
         $tracker->setDomainName($gaConfig['domain_name']);
     }
     if (isset($gaConfig['allow_linker'])) {
         $tracker->setAllowLinker($gaConfig['allow_linker']);
     }
     if (true === $gaConfig['enable_display_advertising']) {
         $tracker->setEnableDisplayAdvertising(true);
     }
     if (true === $gaConfig['anonymize_ip']) {
         $tracker->setAnonymizeIp(true);
     }
     if (false === $gaConfig['enable']) {
         $tracker->setEnableTracking(false);
     }
     return $tracker;
 }
예제 #7
0
 public function testAnonymizeIp()
 {
     $tracker = new Tracker(123);
     $tracker->setAnonymizeIp(true);
     $this->assertTrue($tracker->getAnonymizeIp());
 }