Version Notes
Implements Google Tag Manager into Magento
Download this release
Release Info
Developer | Yireo |
Extension | yireo_googletagmanager |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Yireo/GoogleTagManager/Block/Default.php +33 -0
- app/code/community/Yireo/GoogleTagManager/Helper/Data.php +38 -0
- app/code/community/Yireo/GoogleTagManager/Model/Observer.php +36 -0
- app/code/community/Yireo/GoogleTagManager/etc/config.xml +80 -0
- app/code/community/Yireo/GoogleTagManager/etc/system.xml +55 -0
- app/design/frontend/base/default/layout/googletagmanager.xml +16 -0
- app/design/frontend/base/default/template/googletagmanager/default.phtml +13 -0
- app/etc/modules/Yireo_GoogleTagManager.xml +19 -0
- package.xml +18 -0
app/code/community/Yireo/GoogleTagManager/Block/Default.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* GoogleTagManager plugin for Magento
|
4 |
+
*
|
5 |
+
* @package Yireo_GoogleTagManager
|
6 |
+
* @author Yireo (http://www.yireo.com/)
|
7 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
8 |
+
* @license Open Software License
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Yireo_GoogleTagManager_Block_Default extends Mage_Core_Block_Template
|
12 |
+
{
|
13 |
+
public function _construct()
|
14 |
+
{
|
15 |
+
parent::_construct();
|
16 |
+
$this->setTemplate('googletagmanager/default.phtml');
|
17 |
+
}
|
18 |
+
|
19 |
+
public function isEnabled()
|
20 |
+
{
|
21 |
+
return (bool)$this->getConfig('active');
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getId()
|
25 |
+
{
|
26 |
+
return $this->getConfig('id');
|
27 |
+
}
|
28 |
+
|
29 |
+
public function getConfig($key = null, $default_value = null)
|
30 |
+
{
|
31 |
+
return Mage::helper('googletagmanager')->getConfigValue($key, $default_value);
|
32 |
+
}
|
33 |
+
}
|
app/code/community/Yireo/GoogleTagManager/Helper/Data.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* GoogleTagManager plugin for Magento
|
4 |
+
*
|
5 |
+
* @package Yireo_GoogleTagManager
|
6 |
+
* @author Yireo
|
7 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
8 |
+
* @license Open Software License
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Yireo_GoogleTagManager_Helper_Data extends Mage_Core_Helper_Abstract
|
12 |
+
{
|
13 |
+
public function getConfigValue($key = null, $default_value = null)
|
14 |
+
{
|
15 |
+
$value = Mage::getStoreConfig('googletagmanager/settings/'.$key);
|
16 |
+
if(empty($value)) $value = $default_value;
|
17 |
+
return $value;
|
18 |
+
}
|
19 |
+
|
20 |
+
/*
|
21 |
+
* Usage:
|
22 |
+
* echo Mage::helper('googletagmanager')->getHtml($arguments);
|
23 |
+
* $arguments is an associative array (size, count, url)
|
24 |
+
|
25 |
+
*/
|
26 |
+
public function getHeaderScript()
|
27 |
+
{
|
28 |
+
if (!($layout = Mage::app()->getFrontController()->getAction()->getLayout())) {
|
29 |
+
return '';
|
30 |
+
}
|
31 |
+
|
32 |
+
if (!($block = $layout->getBlock('googletagmanager'))) {
|
33 |
+
return '';
|
34 |
+
}
|
35 |
+
|
36 |
+
return $block->toHtml();
|
37 |
+
}
|
38 |
+
}
|
app/code/community/Yireo/GoogleTagManager/Model/Observer.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* GoogleTagManager plugin for Magento
|
4 |
+
*
|
5 |
+
* @package Yireo_GoogleTagManager
|
6 |
+
* @author Yireo (http://www.yireo.com/)
|
7 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
8 |
+
* @license Open Software License
|
9 |
+
*/
|
10 |
+
|
11 |
+
class Yireo_GoogleTagManager_Model_Observer
|
12 |
+
{
|
13 |
+
/*
|
14 |
+
* Listen to the event core_block_abstract_to_html_after
|
15 |
+
*
|
16 |
+
* @access public
|
17 |
+
* @parameter Varien_Event_Observer $observer
|
18 |
+
* @return $this
|
19 |
+
*/
|
20 |
+
public function coreBlockAbstractToHtmlAfter($observer)
|
21 |
+
{
|
22 |
+
$block = $observer->getEvent()->getBlock();
|
23 |
+
if($block->getNameInLayout() == 'root') {
|
24 |
+
|
25 |
+
$transport = $observer->getEvent()->getTransport();
|
26 |
+
$html = $transport->getHtml();
|
27 |
+
|
28 |
+
$script = Mage::helper('googletagmanager')->getHeaderScript();
|
29 |
+
$html = preg_replace('/\<body([^\>]+)\>/', '\0'.$script, $html);
|
30 |
+
|
31 |
+
$transport->setHtml($html);
|
32 |
+
}
|
33 |
+
|
34 |
+
return $this;
|
35 |
+
}
|
36 |
+
}
|
app/code/community/Yireo/GoogleTagManager/etc/config.xml
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* GoogleTagManager plugin for Magento
|
5 |
+
*
|
6 |
+
* @category design_default
|
7 |
+
* @package Yireo_GoogleTagManager
|
8 |
+
* @author Yireo
|
9 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
10 |
+
* @license Open Software License
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<modules>
|
15 |
+
<Yireo_GoogleTagManager>
|
16 |
+
<version>1.0.0</version>
|
17 |
+
</Yireo_GoogleTagManager>
|
18 |
+
</modules>
|
19 |
+
|
20 |
+
<global>
|
21 |
+
<blocks>
|
22 |
+
<googletagmanager>
|
23 |
+
<class>Yireo_GoogleTagManager_Block</class>
|
24 |
+
</googletagmanager>
|
25 |
+
</blocks>
|
26 |
+
<helpers>
|
27 |
+
<googletagmanager>
|
28 |
+
<class>Yireo_GoogleTagManager_Helper</class>
|
29 |
+
</googletagmanager>
|
30 |
+
</helpers>
|
31 |
+
<models>
|
32 |
+
<googletagmanager>
|
33 |
+
<class>Yireo_GoogleTagManager_Model</class>
|
34 |
+
</googletagmanager>
|
35 |
+
</models>
|
36 |
+
<events>
|
37 |
+
<core_block_abstract_to_html_after>
|
38 |
+
<observers>
|
39 |
+
<googletagmanager_observer>
|
40 |
+
<type>singleton</type>
|
41 |
+
<class>Yireo_GoogleTagManager_Model_Observer</class>
|
42 |
+
<method>coreBlockAbstractToHtmlAfter</method>
|
43 |
+
</googletagmanager_observer>
|
44 |
+
</observers>
|
45 |
+
</core_block_abstract_to_html_after>
|
46 |
+
</events>
|
47 |
+
</global>
|
48 |
+
|
49 |
+
<frontend>
|
50 |
+
<layout>
|
51 |
+
<updates>
|
52 |
+
<googletagmanager>
|
53 |
+
<file>googletagmanager.xml</file>
|
54 |
+
</googletagmanager>
|
55 |
+
</updates>
|
56 |
+
</layout>
|
57 |
+
</frontend>
|
58 |
+
|
59 |
+
<adminhtml>
|
60 |
+
<acl>
|
61 |
+
<resources>
|
62 |
+
<admin>
|
63 |
+
<children>
|
64 |
+
<system>
|
65 |
+
<children>
|
66 |
+
<config>
|
67 |
+
<children>
|
68 |
+
<googletagmanager translate="title" module="googletagmanager">
|
69 |
+
<title>GoogleTagManager</title>
|
70 |
+
</googletagmanager>
|
71 |
+
</children>
|
72 |
+
</config>
|
73 |
+
</children>
|
74 |
+
</system>
|
75 |
+
</children>
|
76 |
+
</admin>
|
77 |
+
</resources>
|
78 |
+
</acl>
|
79 |
+
</adminhtml>
|
80 |
+
</config>
|
app/code/community/Yireo/GoogleTagManager/etc/system.xml
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* GoogleTagManager plugin for Magento
|
5 |
+
*
|
6 |
+
* @category design_default
|
7 |
+
* @package Yireo_GoogleTagManager
|
8 |
+
* @author Yireo
|
9 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
10 |
+
* @license Open Software License
|
11 |
+
*/
|
12 |
+
-->
|
13 |
+
<config>
|
14 |
+
<sections>
|
15 |
+
<googletagmanager translate="label" module="googletagmanager">
|
16 |
+
<label>Google Tag Manager</label>
|
17 |
+
<tab>service</tab>
|
18 |
+
<frontend_type>text</frontend_type>
|
19 |
+
<sort_order>342</sort_order>
|
20 |
+
<show_in_default>1</show_in_default>
|
21 |
+
<show_in_website>1</show_in_website>
|
22 |
+
<show_in_store>1</show_in_store>
|
23 |
+
<groups>
|
24 |
+
<settings translate="label">
|
25 |
+
<label>Settings</label>
|
26 |
+
<frontend_type>text</frontend_type>
|
27 |
+
<sort_order>1</sort_order>
|
28 |
+
<show_in_default>1</show_in_default>
|
29 |
+
<show_in_website>1</show_in_website>
|
30 |
+
<show_in_store>1</show_in_store>
|
31 |
+
<fields>
|
32 |
+
<active translate="label">
|
33 |
+
<label>Enabled</label>
|
34 |
+
<frontend_type>select</frontend_type>
|
35 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
36 |
+
<sort_order>1</sort_order>
|
37 |
+
<show_in_default>1</show_in_default>
|
38 |
+
<show_in_website>1</show_in_website>
|
39 |
+
<show_in_store>1</show_in_store>
|
40 |
+
</active>
|
41 |
+
<id translate="label">
|
42 |
+
<label>Container Public ID</label>
|
43 |
+
<comment><![CDATA[ID of your Google Tag container]]></comment>
|
44 |
+
<frontend_type>text</frontend_type>
|
45 |
+
<sort_order>2</sort_order>
|
46 |
+
<show_in_default>1</show_in_default>
|
47 |
+
<show_in_website>1</show_in_website>
|
48 |
+
<show_in_store>1</show_in_store>
|
49 |
+
</id>
|
50 |
+
</fields>
|
51 |
+
</settings>
|
52 |
+
</groups>
|
53 |
+
</googletagmanager>
|
54 |
+
</sections>
|
55 |
+
</config>
|
app/design/frontend/base/default/layout/googletagmanager.xml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* GoogleTagManager extension for Magento
|
5 |
+
*
|
6 |
+
* @package Yireo_GoogleTagManager
|
7 |
+
* @author Yireo (http://www.yireo.com/)
|
8 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
9 |
+
* @license Open Source License (OSL)
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<layout>
|
13 |
+
<default>
|
14 |
+
<block type="googletagmanager/default" name="googletagmanager" template="googletagmanager/default.phtml" />
|
15 |
+
</default>
|
16 |
+
</layout>
|
app/design/frontend/base/default/template/googletagmanager/default.phtml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* GoogleTagManager plugin for Magento
|
4 |
+
*
|
5 |
+
* @package Yireo_GoogleTagManager
|
6 |
+
* @author Yireo (http://www.yireo.com/)
|
7 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
8 |
+
* @license Open Software License
|
9 |
+
*/
|
10 |
+
?>
|
11 |
+
<?php if($this->isEnabled()) : ?>
|
12 |
+
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $this->getId(); ?>" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','<?php echo $this->getId(); ?>');</script>
|
13 |
+
<?php endif; ?>
|
app/etc/modules/Yireo_GoogleTagManager.xml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Yireo GoogleTagManager-module for Magento
|
5 |
+
*
|
6 |
+
* @package Yireo_GoogleTagManager
|
7 |
+
* @author Yireo (http://www.yireo.com/)
|
8 |
+
* @copyright Copyright (c) 2012 Yireo (http://www.yireo.com/)
|
9 |
+
* @license Open Software License
|
10 |
+
*/
|
11 |
+
-->
|
12 |
+
<config>
|
13 |
+
<modules>
|
14 |
+
<Yireo_GoogleTagManager>
|
15 |
+
<active>true</active>
|
16 |
+
<codePool>community</codePool>
|
17 |
+
</Yireo_GoogleTagManager>
|
18 |
+
</modules>
|
19 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>yireo_googletagmanager</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license>Open Source License</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Implements Google Tag Manager into Magento</summary>
|
10 |
+
<description>Implements Google Tag Manager into Magento</description>
|
11 |
+
<notes>Implements Google Tag Manager into Magento</notes>
|
12 |
+
<authors><author><name>Yireo</name><user>yireo</user><email>info@yireo.com</email></author></authors>
|
13 |
+
<date>2012-10-02</date>
|
14 |
+
<time>11:11:01</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Yireo_GoogleTagManager.xml" hash="ffed7b579c7b75d0f7618d77c2c2b994"/></dir></target><target name="magecommunity"><dir name="Yireo"><dir name="GoogleTagManager"><dir name="Block"><file name="Default.php" hash="ac9e0fa686f8ab0518b67ba96d378957"/></dir><dir name="Helper"><file name="Data.php" hash="d5577fc9ab656bc97ad4a332852c06eb"/></dir><dir name="Model"><file name="Observer.php" hash="89c0ad0e22bf669a0a835e2ac7952825"/></dir><dir name="etc"><file name="config.xml" hash="4618e779a452c171b73a918656f182bc"/><file name="system.xml" hash="fd14e2cabf60a28eb70647e44b02a560"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="googletagmanager.xml" hash="17873ec53b53ef52529d401c125be1e2"/></dir><dir name="template"><dir name="googletagmanager"><file name="default.phtml" hash="beaf3c29e9cb4b479bdb7ca07282b837"/></dir></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.8</min><max>6.0.0</max></php></required></dependencies>
|
18 |
+
</package>
|