├── .gitignore ├── README.md ├── app ├── code │ └── local │ │ └── MagePal │ │ └── GoogleTagManager │ │ ├── Block │ │ ├── GtmCode.php │ │ └── Tm.php │ │ ├── Helper │ │ └── Data.php │ │ ├── Model │ │ ├── DataLayer.php │ │ └── Observer.php │ │ └── etc │ │ ├── adminhtml.xml │ │ ├── config.xml │ │ └── system.xml ├── design │ └── frontend │ │ └── base │ │ └── default │ │ ├── layout │ │ └── magepal_googletagmanager.xml │ │ └── template │ │ └── magepal │ │ └── googletagmanager │ │ ├── data_layer.phtml │ │ ├── gtm_code.phtml │ │ └── gtm_head_code.phtml └── etc │ └── modules │ └── MagePal_GoogleTagManager.xml ├── composer.json └── modman /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | package.box 3 | httpdocs 4 | magento-sample-data*.tar.gz 5 | 6 | # Numerous always-ignore extensions 7 | *.diff 8 | *.err 9 | *.orig 10 | *.log 11 | *.rej 12 | *.swo 13 | *.swp 14 | *.vi 15 | *~ 16 | *.sass-cache 17 | 18 | # OS or Editor folders 19 | .DS_Store 20 | Thumbs.db 21 | .cache 22 | .project 23 | .settings 24 | .tmproj 25 | *.esproj 26 | nbproject 27 | 28 | # Dreamweaver added files 29 | _notes 30 | dwsync.xml 31 | 32 | # Komodo 33 | *.komodoproject 34 | .komodotools 35 | 36 | # Folders to ignore 37 | .hg 38 | .svn 39 | .CVS 40 | .idea 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Magento 2 Extension Marketplace 2 | 3 | # Google Tag Manager for Magento 1.x / OpenMage LTS with Data Layer 4 | 5 | #### Looking to add Google Analytics 4 to your Magento 1 / OpenMage LTS store? 6 | Unlock the power of Google Analytics 4 on your Magento 1 / OpenMage LTS store with our revolutionary new Google Tag Manager extension. Take your e-commerce game to the next level and gain unprecedented insights into your customers' behavior with the most advanced analytics platform available. Upgrade now and get started on your journey towards data-driven success. Learn more about our Google Analytics 4 extension today! 7 | 8 | 9 | Google Tag Manager for Magento 1 (OpenMage LTS) is a powerful extension that allows you to easily manage and deploy marketing and analytics tags on your Magento 1 website. With this extension, you can easily add, edit, and manage your Google Analytics, Google AdWords, TikTok, Bing, Facebook Tags and other marketing and analytics tags without the need for developer assistance. The extension also includes a user-friendly interface that makes it easy to set up and manage your tags. Additionally, it provides the option to use GTM and GA together, this allows you to have full control over your GA tags and triggers, and you can access all the data in GA. This extension is a must-have for any Magento 1 store owner looking to improve their website's tracking and analytics capabilities. 10 | 11 | ### Why use Google Analytics 4 12 | 13 | ## Features 14 | - Quick and easy setup 15 | - Add tag via XML layout 16 | - Add tag via event/observer 17 | - Data layer support 18 | 19 | ### Data layer attributes 20 | --------- 21 | * pageType (i.e catalog_category_view) 22 | * list (cart, category, detail, other) 23 | 24 | #### Customer 25 | * customer.isLoggedIn 26 | * customer.id 27 | * customer.groupId 28 | 29 | #### Category 30 | * category.id 31 | * customer.category 32 | 33 | #### Product 34 | * product.id 35 | * product.name 36 | * product.sku 37 | 38 | #### Cart 39 | * cart.hasItems 40 | * cart.items[].sku 41 | * cart.items[].name 42 | * cart.items[].price 43 | * cart.items[].quantity 44 | * cart.total 45 | * cart.itemCount 46 | * cart.hasCoupons 47 | * cart.couponCode 48 | 49 | #### Transaction 50 | * transactionId 51 | * transactionAffiliation 52 | * transactionTotal 53 | * transactionShipping 54 | * transactionProducts[].sku 55 | * transactionProducts[].name 56 | * transactionProducts[].price 57 | * transactionProducts[].quantity 58 | 59 | **Q: What is GA4 and how does it differ from previous versions of Google Analytics?** 60 | A: GA4 is the latest version of Google Analytics and it has a number of new features and improvements over previous versions. These include enhanced data collection and analysis capabilities, improved data privacy and security, and a more user-friendly interface. 61 | 62 | **Q: Can I use GA4 with my Magento 1 store?** 63 | 64 | A: Yes, you can use GA4 with your Magento 1 store by using a GA4 extension. These extensions allow you to easily integrate GA4 into your Magento 1 website and access all of its new features and capabilities. 65 | 66 | **Q: How do I install a GA4 extension for Magento 1?** 67 | 68 | A: Installing a GA4 extension for Magento 1 is similar to installing any other Magento extension. You will need to download the extension, upload it to your Magento 1 store, and then configure it to work with your website. Some extension providers may offer additional installation assistance. 69 | 70 | **Q: How do I set up GA4 on my Magento 1 store?** 71 | 72 | A: Setting up GA4 on your Magento 1 store will depend on the specific extension you are using. However, the process typically involves creating a GA4 property in your Google Analytics account, obtaining a tracking code, and then configuring the extension to use that tracking code on your website. 73 | 74 | **Q: Will my data from previous versions of Google Analytics be lost if I switch to GA4?** 75 | 76 | A: No, your data from previous versions of Google Analytics will not be lost if you switch to GA4. GA4 will continue to track and collect data from your website, and you will be able to access all of your previous data in your GA4 account. 77 | 78 | **Q: Can I still use Google Tag Manager with GA4 and Magento 1?** 79 | 80 | A: Yes, you can still use Google Tag Manager with GA4 and Magento 1. Many GA4 extensions for Magento 1 also support Google Tag Manager, which allows you to manage and deploy marketing and analytics tags without the need for developer assistance. 81 | 82 | 83 | ## Support 84 | 85 | If you encounter any problems or bugs, please open an issue on [GitHub](https://github.com/magepal/magento2-reindex/issues). 86 | 87 | Need help setting up or want to customize this extension to meet your business needs? Please email support@magepal.com and if we like your idea we will add this feature for free or at a discounted rate. 88 | 89 | ## Magento 2 Extensions 90 | 91 | [Custom SMTP](https://www.magepal.com/magento2/extensions/custom-smtp.html) | [Google Tag Manager](https://www.magepal.com/magento2/extensions/google-tag-manager.html) | [Enhanced E-commerce](https://www.magepal.com/magento2/extensions/enhanced-ecommerce-for-google-tag-manager.html) | [Reindex](https://www.magepal.com/magento2/extensions/reindex.html) | [Custom Shipping Method](https://www.magepal.com/magento2/extensions/custom-shipping-rates-for-magento-2.html) | [Preview Order Confirmation](https://www.magepal.com/magento2/extensions/preview-order-confirmation-page-for-magento-2.html) | [Guest to Customer](https://www.magepal.com/magento2/extensions/guest-to-customer.html) | [Admin Form Fields Manager](https://www.magepal.com/magento2/extensions/admin-form-fields-manager-for-magento-2.html) | [Customer Dashboard Links Manager](https://www.magepal.com/magento2/extensions/customer-dashboard-links-manager-for-magento-2.html) | [Lazy Loader](https://www.magepal.com/magento2/extensions/lazy-load.html) | [Order Confirmation Page Miscellaneous Scripts](https://www.magepal.com/magento2/extensions/order-confirmation-miscellaneous-scripts-for-magento-2.html) 92 | 93 | © MagePal LLC. | [www.magepal.com](http:/www.magepal.com) 94 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/Block/GtmCode.php: -------------------------------------------------------------------------------- 1 | _cookieHelper = Mage::helper('core/cookie'); 32 | $this->_gtmHelper = Mage::helper('googletagmanager'); 33 | } 34 | 35 | /** 36 | * Get Account Id 37 | * 38 | * @return string 39 | */ 40 | public function getAccountId() { 41 | return $this->_gtmHelper->getAccountId(); 42 | } 43 | 44 | /** 45 | * Get Custom Code 46 | * 47 | * @return string 48 | */ 49 | public function getCustomCode() { 50 | return $this->_gtmHelper->getCustomCode(); 51 | } 52 | 53 | /** 54 | * Allow to send personal? 55 | * 56 | * @return string 57 | */ 58 | public function sendPersonal() { 59 | return $this->_gtmHelper->sendPersonal(); 60 | } 61 | 62 | /** 63 | * Render tag manager JS 64 | * 65 | * @return string 66 | */ 67 | protected function _toHtml() { 68 | if ($this->_cookieHelper->isUserNotAllowSaveCookie() || !$this->_gtmHelper->isEnabled()) { 69 | return ''; 70 | } 71 | return parent::_toHtml(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/Block/Tm.php: -------------------------------------------------------------------------------- 1 | _cookieHelper = Mage::helper('core/cookie'); 40 | $this->_gtmHelper = Mage::helper('googletagmanager'); 41 | $this->_dataLayerModel = Mage::getModel('googletagmanager/dataLayer'); 42 | 43 | $this->addVariable('ecommerce', array('currencyCode' => Mage::app()->getStore()->getCurrentCurrencyCode())); 44 | } 45 | 46 | /** 47 | * Render information about specified orders and their items 48 | * 49 | * @return void|string 50 | */ 51 | protected function getOrdersTrackingCode() 52 | { 53 | $collection = $this->getOrderCollection(); 54 | 55 | if(!$collection){ 56 | return; 57 | } 58 | 59 | $result = array(); 60 | 61 | foreach ($collection as $order) { 62 | 63 | foreach ($order->getAllVisibleItems() as $item) { 64 | $product[] = array( 65 | 'sku' => $item->getSku(), 66 | 'name' => $item->getName(), 67 | 'price' => $item->getBasePrice(), 68 | 'quantity' => $item->getQtyOrdered() 69 | ); 70 | } 71 | 72 | $transaction = array( 73 | 'transactionId' => $order->getIncrementId(), 74 | 'transactionAffiliation' => Mage::app()->getStore()->getFrontendName(), 75 | 'transactionTotal' => $order->getBaseGrandTotal(), 76 | 'transactionTax' => $order->getBaseTaxAmount(), 77 | 'transactionShipping' => $order->getBaseShippingAmount(), 78 | 'discountCode' => $order->getCouponCode(), 79 | 'discountPrice' => $order->getDiscountAmount(), 80 | 'transactionProducts' => $product 81 | ); 82 | 83 | 84 | $result[] = sprintf("dataLayer.push(%s);", json_encode($transaction)); 85 | } 86 | 87 | return implode("\n", $result) . "\n"; 88 | } 89 | 90 | /** 91 | * Render tag manager script 92 | * 93 | * @return string 94 | */ 95 | protected function _toHtml() { 96 | if ($this->_cookieHelper->isUserNotAllowSaveCookie() || !$this->_gtmHelper->isEnabled()) { 97 | return ''; 98 | } 99 | 100 | return parent::_toHtml(); 101 | } 102 | 103 | /** 104 | * Return data layer json 105 | * 106 | * @return json 107 | */ 108 | public function getGtmTrackingCode() { 109 | 110 | Mage::dispatchEvent('magepal_data_layer', array('data_layer' => $this)); 111 | 112 | $result = array(); 113 | $result[] = sprintf("dataLayer.push(%s);\n", json_encode($this->_dataLayerModel->getVariables())); 114 | 115 | if(!empty($this->_customVariables) && is_array($this->_customVariables)){ 116 | 117 | foreach($this->_customVariables as $custom){ 118 | $result[] = sprintf("dataLayer.push(%s);\n", json_encode($custom)); 119 | } 120 | } 121 | 122 | return implode("\n", $result) . "\n"; 123 | } 124 | 125 | public function getQuote(){ 126 | return $this->_dataLayerModel->getQuote(); 127 | } 128 | 129 | public function addVariable($name, $value) { 130 | $this->_dataLayerModel->addVariable($name, $value); 131 | 132 | return $this; 133 | } 134 | 135 | public function addCustomVariable($name, $value = null) { 136 | if(is_array($name)){ 137 | $this->_customVariables[] = $name; 138 | } 139 | else{ 140 | $this->_customVariables[] = array($name => $value); 141 | } 142 | 143 | return $this; 144 | } 145 | 146 | public function formatPrice($price){ 147 | return $this->_dataLayerModel->formatPrice($price); 148 | } 149 | 150 | public function getOrderCollection(){ 151 | $orderIds = $this->getOrderIds(); 152 | if (empty($orderIds) || !is_array($orderIds)) { 153 | return; 154 | } 155 | 156 | $this->_orderCollection = Mage::getResourceModel('sales/order_collection') 157 | ->addFieldToFilter('entity_id', array('in' => $orderIds)); 158 | 159 | return $this->_orderCollection; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/Helper/Data.php: -------------------------------------------------------------------------------- 1 | _customerSession = Mage::getSingleton('customer/session'); 42 | 43 | $this->fullActionName = Mage::app()->getFrontController()->getAction() ? Mage::app()->getFrontController()->getAction()->getFullActionName() : 'Unknown';; 44 | 45 | $this->addVariable('pageType', $this->fullActionName); 46 | $this->addVariable('list', 'other'); 47 | 48 | $this->setCustomerDataLayer(); 49 | $this->setProductDataLayer(); 50 | $this->setCategoryDataLayer(); 51 | $this->setCartDataLayer(); 52 | 53 | } 54 | 55 | /** 56 | * Return Data Layer Variables 57 | * 58 | * @return array 59 | */ 60 | public function getVariables() { 61 | return $this->_variables; 62 | } 63 | 64 | /** 65 | * Add Variables 66 | * @param string $name 67 | * @param mix $value 68 | * @return MagePal\GoogleTagManager\Model\DataLayer 69 | */ 70 | public function addVariable($name, $value) { 71 | 72 | if (!empty($name)) { 73 | $this->_variables[$name] = $value; 74 | } 75 | 76 | return $this; 77 | } 78 | 79 | 80 | /** 81 | * Set category Data Layer 82 | */ 83 | protected function setCategoryDataLayer() { 84 | if($this->fullActionName === 'catalog_category_view' 85 | && $_category = Mage::registry('current_category') 86 | ) { 87 | $category = array(); 88 | $category['id'] = $_category->getId(); 89 | $category['name'] = $_category->getName(); 90 | 91 | $this->addVariable('category', $category); 92 | 93 | $this->addVariable('list', 'category'); 94 | } 95 | 96 | return $this; 97 | } 98 | 99 | 100 | /** 101 | * Set product Data Layer 102 | */ 103 | protected function setProductDataLayer() { 104 | if($this->fullActionName === 'catalog_product_view' 105 | && $_product = Mage::registry('current_product') 106 | ) { 107 | $this->addVariable('list', 'detail'); 108 | 109 | $product = array(); 110 | $product['id'] = $_product->getId(); 111 | $product['sku'] = $_product->getSku(); 112 | $product['name'] = $_product->getName(); 113 | // $this->addVariable('productPrice', $_product->getPrice()); 114 | $this->addVariable('product', $product); 115 | } 116 | 117 | return $this; 118 | } 119 | 120 | /** 121 | * Set Customer Data Layer 122 | */ 123 | protected function setCustomerDataLayer() { 124 | $customer = array(); 125 | if ($this->_customerSession->isLoggedIn()) { 126 | $customer['isLoggedIn'] = true; 127 | if (Mage::helper('googletagmanager')->sendPersonal()) { 128 | $customer['id'] = $this->_customerSession->getCustomerId(); 129 | $customer['groupId'] = $this->_customerSession->getCustomerGroupId(); 130 | } 131 | //$customer['groupCode'] = ; 132 | } else { 133 | $customer['isLoggedIn'] = false; 134 | } 135 | 136 | $this->addVariable('customer', $customer); 137 | 138 | return $this; 139 | } 140 | 141 | 142 | /** 143 | * Set cart Data Layer 144 | */ 145 | protected function setCartDataLayer() { 146 | if($this->fullActionName === 'checkout_index_index'){ 147 | $this->addVariable('list', 'cart'); 148 | } 149 | 150 | $quote = $this->getQuote(); 151 | $cart = array(); 152 | 153 | $cart['hasItems'] = false; 154 | 155 | if ($quote->getItemsCount()) { 156 | $items = array(); 157 | 158 | // set items 159 | foreach($quote->getAllVisibleItems() as $item){ 160 | $items[] = array( 161 | 'sku' => $item->getSku(), 162 | 'name' => $item->getName(), 163 | 'price' => $this->formatPrice($item->getPrice()), 164 | 'quantity' => $item->getQty() 165 | ); 166 | } 167 | 168 | if(count($items) > 0){ 169 | $cart['hasItems'] = true; 170 | $cart['items'] = $items; 171 | } 172 | $cart['total'] = $this->formatPrice($quote->getGrandTotal()); 173 | $cart['itemCount'] = $quote->getItemsCount(); 174 | 175 | 176 | //set coupon code 177 | $coupon = $quote->getCouponCode(); 178 | 179 | $cart['hasCoupons'] = $coupon ? true : false; 180 | 181 | if($coupon){ 182 | $cart['couponCode'] = $coupon; 183 | } 184 | } 185 | 186 | $this->addVariable('cart', $cart); 187 | 188 | return $this; 189 | } 190 | 191 | 192 | /** 193 | * Get active quote 194 | * 195 | * @return Quote 196 | */ 197 | public function getQuote() 198 | { 199 | if (null === $this->_quote) { 200 | $this->_quote = Mage::getSingleton('checkout/cart')->getQuote(); 201 | } 202 | return $this->_quote; 203 | } 204 | 205 | public function formatPrice($price){ 206 | return Mage::getModel('directory/currency')->format( 207 | $price, 208 | array('display'=>Zend_Currency::NO_SYMBOL), 209 | false 210 | ); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/Model/Observer.php: -------------------------------------------------------------------------------- 1 | getEvent()->getOrderIds(); 18 | if (empty($orderIds) || !is_array($orderIds)) { 19 | return; 20 | } 21 | $block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('magepal_gtm_datalayer'); 22 | if ($block) { 23 | $block->setOrderIds($orderIds); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/etc/adminhtml.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Google Tag Manager 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 1.0.5 13 | 14 | 15 | 16 | 17 | 18 | MagePal_GoogleTagManager_Model 19 | 20 | 21 | 22 | 23 | MagePal_GoogleTagManager_Block 24 | 25 | 26 | 27 | 28 | MagePal_GoogleTagManager_Helper 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | MagePal_GoogleTagManager.csv 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | googletagmanager/observer 47 | setGoogleTagManagerOnOrderSuccessPageView 48 | 49 | 50 | 51 | 52 | 53 | 54 | googletagmanager/observer 55 | setgoogletagmanagerOnOrderSuccessPageView 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | magepal_googletagmanager.xml 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | magepal_googletagmanager.csv 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /app/code/local/MagePal/GoogleTagManager/etc/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 900 14 | 15 | 16 | 17 | 18 | 19 | magepal 20 | text 21 | 340 22 | 1 23 | 1 24 | 1 25 | Google Analytics 4 Features.]]> 26 | 27 | 28 | 29 | text 30 | 10 31 | 1 32 | 1 33 | 1 34 | 35 | 36 | 37 | select 38 | adminhtml/system_config_source_yesno 39 | 10 40 | 1 41 | 1 42 | 1 43 | 44 | 45 | 46 | text 47 | 20 48 | 1 49 | 1 50 | 1 51 | 52 | 53 | 54 | textarea 55 | 30 56 | 1 57 | 1 58 | 1 59 | 60 | 61 | 62 | 63 | select 64 | adminhtml/system_config_source_yesno 65 | 40 66 | 1 67 | 1 68 | 1 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/layout/magepal_googletagmanager.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/magepal/googletagmanager/data_layer.phtml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 17 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/magepal/googletagmanager/gtm_code.phtml: -------------------------------------------------------------------------------- 1 | 9 | 10 | getAccountId(); ?> 11 | 12 | 13 | 15 | -------------------------------------------------------------------------------- /app/design/frontend/base/default/template/magepal/googletagmanager/gtm_head_code.phtml: -------------------------------------------------------------------------------- 1 | 9 | 10 | getAccountId(); ?> 11 | 12 | 13 | 18 | 19 | 20 | getCustomCode(); ?> 21 | 22 | 0): ?> 23 | 24 | 25 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/etc/modules/MagePal_GoogleTagManager.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | local 7 | 8 | 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magepal/magento1-google-tag-manager", 3 | "description":"Google Tag Manager (GTM) for Magento with Advanced Data Layer", 4 | "keywords": [ 5 | "magento", 6 | "gtm", 7 | "google tag manager", 8 | "ga", 9 | "data layer", 10 | "Tag Manager" 11 | ], 12 | "license": "OSL-3.0", 13 | "type": "magento-module", 14 | "require": { 15 | "php": ">=5.3.0" 16 | }, 17 | "extra": { 18 | "auto-append-gitignore": true 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /modman: -------------------------------------------------------------------------------- 1 | # Modman file generated by 'generate-modman' 2 | # app/code 3 | app/code/local/MagePal/GoogleTagManager app/code/local/MagePal/GoogleTagManager 4 | # app/etc 5 | app/etc/modules/MagePal_GoogleTagManager.xml app/etc/modules/MagePal_GoogleTagManager.xml 6 | # app/design 7 | app/design/frontend/base/default/layout/magepal_googletagmanager.xml app/design/frontend/base/default/layout/magepal_googletagmanager.xml 8 | app/design/frontend/base/default/template/magepal/googletagmanager/data_layer.phtml app/design/frontend/base/default/template/magepal/googletagmanager/data_layer.phtml 9 | app/design/frontend/base/default/template/magepal/googletagmanager/gtm_code.phtml app/design/frontend/base/default/template/magepal/googletagmanager/gtm_code.phtml 10 | app/design/frontend/base/default/template/magepal/googletagmanager/gtm_head_code.phtml app/design/frontend/base/default/template/magepal/googletagmanager/gtm_head_code.phtml 11 | --------------------------------------------------------------------------------