/** * Render regular page tracking javascript code * The custom "page name" may be set from layout or somewhere else. It must start from slash. * - Override of Mage_GoogleAnalytics_Block_Ga::_getPageTrackingCodeUniversal() * * @param string $accountId * @return string */ protected function _getPageTrackingCodeUniversal($accountId) { if (!$this->helper('enhancedecommerce')->isEnabled()) { return parent::_getPageTrackingCodeUniversal($accountId); } return "\nga('create', '{$this->jsQuoteEscape($accountId)}', 'auto');\n" . $this->_getAnonymizationCode() . "\nga('require', 'ec');\n"; }
/** * Render GA tracking scripts * * @return string */ protected function _toHtml() { if (!$this->_isAvailable()) { return ''; } return parent::_toHtml(); }
/** * Prepare and return block's html output * * @return string Google Analytics JS Tracking Code */ protected function _toHtml() { $html = parent::_toHtml(); if (!Mage::getStoreConfigFlag(self::CONFIG_GOOGLE_ANALYTICS_IP_ANONYMIZATION)) { return $html; } $matches = array(); $setAccountExpression = '/_gaq\\.push\\(\\[\'_setAccount\', \'[a-zA-Z0-9-_]+\'\\]\\);\\n/'; $append = '_gaq.push([\'_gat._anonymizeIp\']);'; if (preg_match_all($setAccountExpression, $html, $matches) && count($matches) && count($matches[0])) { $html = preg_replace($setAccountExpression, $matches[0][0] . $append . "\n", $html); } return $html; }
/** * Render information about specified orders and their items * * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans * @param bool $accountId2 * @return string */ protected function _getOrdersTrackingCode($accountId2 = false) { if (Mage::helper('googleanalyticsplus')->getGoogleanalyticsplusStoreConfig('convertcurrencyenabled')) { $orderIds = $this->getOrderIds(); if (empty($orderIds) || !is_array($orderIds)) { return; } $collection = Mage::getResourceModel('sales/order_collection')->addFieldToFilter('entity_id', array('in' => $orderIds)); $result = array(); foreach ($collection as $order) { if ($order->getIsVirtual()) { $address = $order->getBillingAddress(); } else { $address = $order->getShippingAddress(); } $result[] = sprintf("_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);", $order->getIncrementId(), Mage::app()->getStore()->getFrontendName(), Mage::helper('googleanalyticsplus')->convert($order, 'getBaseGrandTotal'), Mage::helper('googleanalyticsplus')->convert($order, 'getBaseTaxAmount'), Mage::helper('googleanalyticsplus')->convert($order, 'getBaseShippingAmount'), $this->jsQuoteEscape($address->getCity()), $this->jsQuoteEscape($address->getRegion()), $this->jsQuoteEscape($address->getCountry())); foreach ($order->getAllVisibleItems() as $item) { $result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);", $order->getIncrementId(), $this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()), null, Mage::helper('googleanalyticsplus')->convert($order, 'getBasePrice', $item), $item->getQtyOrdered()); } $result[] = "_gaq.push(['_trackTrans']);"; $html = implode("\n", $result); } } else { $html = "\n" . parent::_getOrdersTrackingCode(); } if ($accountId2) { $html .= str_replace('_gaq.push([\'_', '_gaq.push([\'t2._', $html); } return $html; }
/** * Transaction on Mage 1.4.2 + * duplicate for secondary tracker */ protected function _getOrdersTrackingCode($accountId2 = false) { $html = "\n" . parent::_getOrdersTrackingCode(); if ($accountId2) { $html .= str_replace('_gaq.push([\'_', '_gaq.push([\'t2._', $html); } return $html; }