Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code updates #28

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/code/local/MagePal/GoogleTagManager/Block/Tm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class MagePal_GoogleTagManager_Block_Tm extends Mage_Core_Block_Template
*/
protected $_dataLayerModel = null;


protected $_customVariables = array();

protected $_orderCollection = null;
Expand All @@ -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');
}

}

/**
Expand Down
47 changes: 36 additions & 11 deletions app/code/local/MagePal/GoogleTagManager/Model/DataLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();

Expand All @@ -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()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Default layout, loads most of the pages

<default>
<reference name="head">
<block type="googletagmanager/tm" name="magepal_gtm_datalayer" as="magepal_gtm_datalayer" template="magepal/googletagmanager/data_layer.phtml" />
<block type="googletagmanager/tm" name="gtm_datalayer" as="gtm_datalayer" template="magepal/googletagmanager/data_layer.phtml" />
<block type="googletagmanager/gtmCode" name="gtm_head_code" as="gtm_head_code" template="magepal/googletagmanager/gtm_head_code.phtml" />
</reference>
<reference name="after_body_start">
Expand Down