From 90e350f06c6bacc178f1361c8f61eee5c24893f6 Mon Sep 17 00:00:00 2001 From: alexnos88 Date: Thu, 29 May 2014 00:30:14 -0700 Subject: [PATCH 1/2] Update Ga.php update google analytics from ga.js to analytics.js - php block --- app/code/Magento/GoogleAnalytics/Block/Ga.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/GoogleAnalytics/Block/Ga.php b/app/code/Magento/GoogleAnalytics/Block/Ga.php index 30ebc39fda8db..798238bd234bd 100644 --- a/app/code/Magento/GoogleAnalytics/Block/Ga.php +++ b/app/code/Magento/GoogleAnalytics/Block/Ga.php @@ -94,9 +94,9 @@ public function getPageTrackingCode($accountId) if ($pageName && substr($pageName, 0, 1) == '/' && strlen($pageName) > 1) { $optPageURL = ", '{$this->escapeJsQuote($pageName)}'"; } - return "\n_gaq.push(['_setAccount', '{$this->escapeJsQuote( + return "\nga('create', '{$this->escapeJsQuote( $accountId - )}']);\n_gaq.push(['_trackPageview'{$optPageURL}]);\n"; + )}');\nga('send', 'pageview'{$optPageURL});\n"; } /** @@ -114,7 +114,7 @@ public function getOrdersTrackingCode() $collection = $this->_salesOrderCollection->create(); $collection->addFieldToFilter('entity_id', array('in' => $orderIds)); - $result = array(); + $result = array( "ga('require', 'ecommerce', 'ecommerce.js');" ); foreach ($collection as $order) { if ($order->getIsVirtual()) { $address = $order->getBillingAddress(); @@ -122,28 +122,25 @@ public function getOrdersTrackingCode() $address = $order->getShippingAddress(); } $result[] = sprintf( - "_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);", + "ga('ecommerce:addTransaction', {'id':'%s', 'affiliation':'%s', 'revenue':'%s', 'shipping':'%s', 'tax':'%s'});", $order->getIncrementId(), $this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()), $order->getBaseGrandTotal(), - $order->getBaseTaxAmount(), $order->getBaseShippingAmount(), - $this->escapeJsQuote($this->escapeHtml($address->getCity())), - $this->escapeJsQuote($this->escapeHtml($address->getRegion())), - $this->escapeJsQuote($this->escapeHtml($address->getCountry())) + $order->getBaseTaxAmount() ); foreach ($order->getAllVisibleItems() as $item) { $result[] = sprintf( - "_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);", + "ga('ecommerce:addItem', {'id':'%s', 'name':'%s', 'sku':'%s', 'category':'%s', 'price':'%s', 'quantity':'%s'});", $order->getIncrementId(), - $this->escapeJsQuote($item->getSku()), $this->escapeJsQuote($item->getName()), + $this->escapeJsQuote($item->getSku()), null, // there is no "category" defined for the order item $item->getBasePrice(), $item->getQtyOrdered() ); } - $result[] = "_gaq.push(['_trackTrans']);"; + $result[] = "ga('ecommerce:send');"; } return implode("\n", $result); } From 3fc9169542332dad745ea4843e861e810c406284 Mon Sep 17 00:00:00 2001 From: alexnos88 Date: Thu, 5 Jun 2014 13:50:19 +0400 Subject: [PATCH 2/2] Update Ga.php replace ecommerce.js with ec.js --- app/code/Magento/GoogleAnalytics/Block/Ga.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/GoogleAnalytics/Block/Ga.php b/app/code/Magento/GoogleAnalytics/Block/Ga.php index 798238bd234bd..93bc4f2c7f26a 100644 --- a/app/code/Magento/GoogleAnalytics/Block/Ga.php +++ b/app/code/Magento/GoogleAnalytics/Block/Ga.php @@ -114,7 +114,7 @@ public function getOrdersTrackingCode() $collection = $this->_salesOrderCollection->create(); $collection->addFieldToFilter('entity_id', array('in' => $orderIds)); - $result = array( "ga('require', 'ecommerce', 'ecommerce.js');" ); + $result = array( "ga('require', 'ec', 'ec.js');" ); foreach ($collection as $order) { if ($order->getIsVirtual()) { $address = $order->getBillingAddress();