/** * Actually execute the GoogleAnalytics tracking * @param Database_Result * @param IsotopeProductCollection $objOrder */ protected function trackGATransaction($objConfig, $objOrder) { // Initilize GA Tracker $tracker = new \UnitedPrototype\GoogleAnalytics\Tracker($objConfig->ga_account, \Environment::get('base')); // Assemble Visitor information // (could also get unserialized from database) $visitor = new \UnitedPrototype\GoogleAnalytics\Visitor(); $visitor->setIpAddress(\Environment::get('ip')); $visitor->setUserAgent(\Environment::get('httpUserAgent')); $transaction = new \UnitedPrototype\GoogleAnalytics\Transaction(); $transaction->setOrderId($objOrder->document_number); $transaction->setAffiliation($objConfig->name); $transaction->setTotal($objOrder->getTotal()); $transaction->setTax($objOrder->getTotal() - $objOrder->getTaxFreeTotal()); // $transaction->setShipping($objOrder->shippingTotal); $objAddress = $objOrder->getBillingAddress(); $transaction->setCity($objAddress->city); if ($objAddress->subdivision) { $arrSub = explode("-", $objAddress->subdivision, 2); $transaction->setRegion($arrSub[1]); } $transaction->setCountry($objAddress->country); /** @var \Isotope\Model\ProductCollectionItem $objItem */ foreach ($objOrder->getItems() as $objItem) { $item = new \UnitedPrototype\GoogleAnalytics\Item(); if ($objItem->getSku()) { $item->setSku($objItem->getSku()); } else { $item->setSku('product' . $objItem->product_id); } $item->setName($objItem->getName()); $item->setPrice($objItem->getPrice()); $item->setQuantity($objItem->quantity); $arrOptionValues = array(); foreach ($objItem->getConfiguration() as $option) { $arrOptionValues[] = (string) $option; } if (!empty($arrOptionValues)) { $item->setVariation(implode(', ', $arrOptionValues)); } $transaction->addItem($item); } // Track logged-in member as custom variable if ($objConfig->ga_member != '' && $objOrder->member > 0 && ($objMember = \MemberModel::findByPk($objOrder->member)) !== null) { $customVar = new \UnitedPrototype\GoogleAnalytics\CustomVariable(1, 'Member', $this->parseSimpleTokens($objConfig->ga_member, $objMember->row()), \UnitedPrototype\GoogleAnalytics\CustomVariable::SCOPE_VISITOR); $tracker->addCustomVariable($customVar); } // Assemble Session information // (could also get unserialized from PHP session) $session = new \UnitedPrototype\GoogleAnalytics\Session(); $tracker->trackTransaction($transaction, $session, $visitor); }
protected function ga($hash, $url_id, $url) { $item = '/Wash/' . $hash . '/' . $url_id; $tracker = new \UnitedPrototype\GoogleAnalytics\Tracker($this->config['ga']['id'], $this->config['ga']['site']); $visitor = new \UnitedPrototype\GoogleAnalytics\Visitor(); $visitor->setIpAddress($_SERVER['REMOTE_ADDR']); $visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']); $visitor->setScreenResolution('1x1'); $session = new \UnitedPrototype\GoogleAnalytics\Session(); $page = new \UnitedPrototype\GoogleAnalytics\Page($item); $page->setTitle($url); $tracker->trackPageview($page, $session, $visitor); }
public function onAfterRoute() { if (JFactory::getApplication()->isAdmin() || !$this->params->get('code') || !$this->params->get('domain') || !$this->params->get('extensions')) { return; } $uri = JUri::getInstance(); $extensions = array_filter(explode(';', $this->params->get('extensions'))); $extension = pathinfo($uri->getPath(), PATHINFO_EXTENSION); if (!in_array($extension, $extensions)) { return; } require_once JPATH_LIBRARIES . '/php-ga/autoload.php'; $tracker = new UnitedPrototype\GoogleAnalytics\Tracker($this->params->get('code'), $this->params->get('domain')); $visitor = new UnitedPrototype\GoogleAnalytics\Visitor(); $visitor->setIpAddress($_SERVER['REMOTE_ADDR']); $visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']); $session = new UnitedPrototype\GoogleAnalytics\Session(); $page = new UnitedPrototype\GoogleAnalytics\Page($uri->getPath()); $tracker->trackPageview($page, $session, $visitor); }