diff --git a/app/code/local/MagePal/GoogleTagManager/Block/Tm.php b/app/code/local/MagePal/GoogleTagManager/Block/Tm.php index edf5a55..cfe244a 100755 --- a/app/code/local/MagePal/GoogleTagManager/Block/Tm.php +++ b/app/code/local/MagePal/GoogleTagManager/Block/Tm.php @@ -28,7 +28,6 @@ class MagePal_GoogleTagManager_Block_Tm extends Mage_Core_Block_Template */ protected $_dataLayerModel = null; - protected $_customVariables = array(); protected $_orderCollection = null; @@ -41,6 +40,14 @@ public function __construct() { $this->_dataLayerModel = Mage::getModel('googletagmanager/dataLayer'); $this->addVariable('ecommerce', array('currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode())); + + $this->addVariable('page_handle', $this->fullActionName); + $this->addVariable('route', 'other'); + + if($this->fullActionName === 'checkout_onepage_success'){ + $this->addVariable('route', 'checkout_success'); + } + } /** diff --git a/app/code/local/MagePal/GoogleTagManager/Model/DataLayer.php b/app/code/local/MagePal/GoogleTagManager/Model/DataLayer.php index 4af2808..79d1025 100755 --- a/app/code/local/MagePal/GoogleTagManager/Model/DataLayer.php +++ b/app/code/local/MagePal/GoogleTagManager/Model/DataLayer.php @@ -42,9 +42,27 @@ public function __construct() { $this->fullActionName = Mage::app()->getFrontController()->getAction() ? Mage::app()->getFrontController()->getAction()->getFullActionName() : 'Unknown';; - $this->addVariable('pageType', $this->fullActionName); - $this->addVariable('list', 'other'); - + $this->addVariable('page_handle', $this->fullActionName); + $this->addVariable('route', 'other'); + + if($this->fullActionName === 'cms_index_index'){ + $this->addVariable('route', 'home_page'); + } + + if($this->fullActionName === 'cms_page_view'){ + $this->addVariable('route', 'cms_page'); + } + + $domain = 'unknown'; // Maybe add $_SERVER['HTTP_HOST']; + if ($_SERVER['HTTP_HOST']) { + $domain = $_SERVER['HTTP_HOST']; + } else if (Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB)) { + $domain = Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB); + } + $domain = preg_replace("(^https?://)", "", $domain); + $domain = preg_replace("(\/)", "", $domain); + $this->addVariable('domain', $domain); + $this->setCustomerDataLayer(); $this->setProductDataLayer(); $this->setCategoryDataLayer(); @@ -89,8 +107,7 @@ protected function setCategoryDataLayer() { $category['name'] = $_category->getName(); $this->addVariable('category', $category); - - $this->addVariable('list', 'category'); + $this->addVariable('route', 'category'); } return $this; @@ -104,13 +121,13 @@ protected function setProductDataLayer() { if($this->fullActionName === 'catalog_product_view' && $_product = Mage::registry('current_product') ) { - $this->addVariable('list', 'detail'); + $this->addVariable('route', 'product'); $product = array(); $product['id'] = $_product->getId(); $product['sku'] = $_product->getSku(); $product['name'] = $_product->getName(); - // $this->addVariable('productPrice', $_product->getPrice()); + $product['price'] = $_product->getPrice(); $this->addVariable('product', $product); } @@ -143,10 +160,18 @@ protected function setCustomerDataLayer() { * Set cart Data Layer */ protected function setCartDataLayer() { - if($this->fullActionName === 'checkout_index_index'){ - $this->addVariable('list', 'cart'); + if($this->fullActionName === 'checkout_index_index' || $this->fullActionName === 'checkout_cart_index'){ + $this->addVariable('route', 'cart'); } - + + if($this->fullActionName === 'checkout_onepage_index'){ + $this->addVariable('route', 'checkout'); + } + + if($this->fullActionName === 'checkout_onepage_success'){ + $this->addVariable('route', 'checkout_success'); + } + $quote = $this->getQuote(); $cart = array(); @@ -160,7 +185,7 @@ protected function setCartDataLayer() { $items[] = array( 'sku' => $item->getSku(), 'name' => $item->getName(), - 'price' => $this->formatPrice($item->getPrice()), + 'price' => $this->formatPrice($item->getRowTotalInclTax()), 'quantity' => $item->getQty() ); } diff --git a/app/design/frontend/base/default/layout/magepal_googletagmanager.xml b/app/design/frontend/base/default/layout/magepal_googletagmanager.xml index 5e8daf2..8f01a6a 100755 --- a/app/design/frontend/base/default/layout/magepal_googletagmanager.xml +++ b/app/design/frontend/base/default/layout/magepal_googletagmanager.xml @@ -14,7 +14,7 @@ Default layout, loads most of the pages - +