Anaraky_GDRT_1 - Version 1.0.1

Version Notes

First stable release

Download this release

Release Info

Developer Vladas Tomkevicius
Extension Anaraky_GDRT_1
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/community/Anaraky/Gdrt/Block/Script.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Anaraky_Gdrt_Block_Script extends Mage_Core_Block_Abstract {
3
+
4
+ private function getParams()
5
+ {
6
+ $type = $this->getData('pageType');
7
+ $params = array('ecomm_pagetype' => 'siteview');
8
+ switch ($type) {
9
+ case 'home':
10
+ $params = array( 'ecomm_pagetype' => 'home');
11
+ break;
12
+
13
+ case 'searchresults':
14
+ $params = array( 'ecomm_pagetype' => 'searchresults');
15
+ break;
16
+
17
+ case 'category':
18
+ $category = Mage::registry('current_category');
19
+ $params = array(
20
+ 'ecomm_pagetype' => 'category',
21
+ 'ecomm_category' => (string)$category->getName()
22
+ );
23
+ unset($category);
24
+ break;
25
+
26
+ case 'product':
27
+ $product = Mage::registry('current_product');
28
+ $params = array(
29
+ 'ecomm_prodid' => (string)$product->getSku(),
30
+ 'ecomm_pagetype' => 'product',
31
+ 'ecomm_totalvalue' => (float)number_format($product->getFinalPrice(), '2', '.', '')
32
+ );
33
+ unset($product);
34
+ break;
35
+
36
+ case 'cart':
37
+ $cart = Mage::getSingleton('checkout/session')->getQuote();
38
+ $items = $cart->getAllVisibleItems();
39
+ if (count($items) > 0) {
40
+ $data = array();
41
+
42
+ foreach ($items as $item)
43
+ {
44
+ $data[0][] = (string)$item->getSku();
45
+ $data[1][] = (int)$item->getQty();
46
+ }
47
+
48
+ $params = array(
49
+ 'ecomm_prodid' => $data[0],
50
+ 'ecomm_pagetype' => 'cart',
51
+ 'ecomm_quantity' => $data[1],
52
+ 'ecomm_totalvalue' => (float)number_format($cart->getGrandTotal(), '2', '.', '')
53
+ );
54
+ }
55
+ else
56
+ $params = array( 'ecomm_pagetype: "cart"' );
57
+
58
+ unset($cart, $items, $item, $data);
59
+ break;
60
+
61
+ case 'purchase':
62
+ $cart = Mage::getSingleton('checkout/session')->getQuote();
63
+ $items = $cart->getAllVisibleItems();
64
+ $data = array();
65
+
66
+ foreach ($items as $item)
67
+ {
68
+ $data[0][] = (string)$item->getSku();
69
+ $data[1][] = (int)$item->getQty();
70
+ }
71
+
72
+ $params = array(
73
+ 'ecomm_prodid' => $data[0],
74
+ 'ecomm_pagetype' => 'purchase',
75
+ 'ecomm_quantity' => $data[1],
76
+ 'ecomm_totalvalue' => (float)number_format($cart->getGrandTotal(), '2', '.', '')
77
+ );
78
+ break;
79
+
80
+ default:
81
+ break;
82
+ }
83
+
84
+ return $params;
85
+ }
86
+
87
+ private function paramsToJS($params)
88
+ {
89
+ $result = array();
90
+
91
+ foreach ($params as $key => $value)
92
+ {
93
+ if (is_array($value) && count($value) == 1)
94
+ $value = $value[0];
95
+
96
+ if (is_array($value))
97
+ {
98
+ if (is_string($value[0]))
99
+ $value = '["' . implode('","', $value) . '"]';
100
+ else
101
+ $value = '[' . implode(',', $value) . ']';
102
+ }
103
+ elseif (is_string($value))
104
+ $value = '"' . $value . '"';
105
+
106
+ $result[] = '\'' . $key . '\': ' . $value;
107
+ }
108
+
109
+ return PHP_EOL . "\t" . implode(',' . PHP_EOL . "\t", $result) . PHP_EOL;
110
+ }
111
+
112
+ private function paramsToURL($params)
113
+ {
114
+ $result = array();
115
+
116
+ foreach ($params as $key => $value)
117
+ {
118
+ if (is_array($value))
119
+ $value = implode(',', $value);
120
+
121
+ $result[] = $key . '=' . $value;
122
+ }
123
+
124
+ return urlencode(implode(';', $result));
125
+ }
126
+
127
+ protected function _toHtml()
128
+ {
129
+ $storeId = Mage::app()->getStore()->getId();
130
+ $gcId = (int)Mage::getStoreConfig('gdrt/general/gc_id', $storeId);
131
+ $gcLabel = trim(Mage::getStoreConfig('gdrt/general/gc_label', $storeId));
132
+ $gcParams = $this->getParams();
133
+
134
+ $s = PHP_EOL .
135
+ '<script type="text/javascript">' . PHP_EOL .
136
+ '/* <![CDATA[ */' . PHP_EOL .
137
+ 'var window.google_tag_params = {' . $this->paramsToJS($gcParams) . '};' . PHP_EOL .
138
+ 'var google_conversion_id = ' . $gcId . ';' . PHP_EOL .
139
+ (!empty($gcLabel) ? 'var google_conversion_label = "' . $gcLabel . '";' . PHP_EOL : '') .
140
+ 'var google_custom_params = window.google_tag_params;' . PHP_EOL .
141
+ 'var google_remarketing_only = true;' . PHP_EOL .
142
+ '/* ]]> */' . PHP_EOL .
143
+ '</script>' . PHP_EOL .
144
+ '<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">' . PHP_EOL .
145
+ '</script>' . PHP_EOL .
146
+ '<noscript>' . PHP_EOL .
147
+ '<div style="display:inline;">' . PHP_EOL .
148
+ '<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/' . $gcId . '/?value=0' . (!empty($gcLabel) ? '&amp;label=' . $gcLabel : '') . '&amp;guid=ON&amp;script=0&amp;data=' . $this->paramsToURL($gcParams) . '"/>' . PHP_EOL .
149
+ '</div>' . PHP_EOL .
150
+ '</noscript>';
151
+
152
+ return $s;
153
+ }
154
+ }
app/code/community/Anaraky/Gdrt/Helper/Data.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Anaraky_Gdrt_Helper_Data extends Mage_Core_Helper_Abstract {
3
+
4
+ }
app/code/community/Anaraky/Gdrt/Model/Observer.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Anaraky_Gdrt_Model_Observer {
3
+
4
+ public function addGdrtBlock(Varien_Event_Observer $observer) {
5
+ if (Mage::getStoreConfig('gdrt/general/gdrt_enable', Mage::app()->getStore()->getId()) === "1")
6
+ {
7
+ $gdrtPages = Mage::getStoreConfig('gdrt/pages');
8
+ $mName = Mage::app()->getRequest()->getModuleName();
9
+ $cName = Mage::app()->getRequest()->getControllerName();
10
+ $aName = Mage::app()->getRequest()->getActionName();
11
+ $pageType = 'other';
12
+
13
+ foreach ($gdrtPages as $k => $v)
14
+ {
15
+ $v = rtrim($v, '/');
16
+ if ($mName . '/' . $cName . '/' . $aName == $v ||
17
+ $mName . '/' . $cName == $v)
18
+ {
19
+ $pageType = $k;
20
+ }
21
+ }
22
+
23
+ $layout = $observer->getEvent()->getLayout();
24
+ $block = '<reference name="before_body_end">
25
+ <block type="gdrt/script" name="gdrt_block">
26
+ <action method="setData">
27
+ <key>pageType</key>
28
+ <value>' . $pageType . '</value>
29
+ </action>
30
+ </block>
31
+ </reference>';
32
+ $layout->getUpdate()->addUpdate($block);
33
+ return $this;
34
+ }
35
+ }
36
+ }
app/code/community/Anaraky/Gdrt/etc/adminhtml.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Allow Everything</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <gdrt translate="title">
15
+ <title>Anaraky GDRT - All</title>
16
+ </gdrt>
17
+ </children>
18
+ </config>
19
+ </children>
20
+ </system>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+ </config>
app/code/community/Anaraky/Gdrt/etc/config.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Anaraky_Gdrt>
5
+ <version>1.0.1</version>
6
+ </Anaraky_Gdrt>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <gdrt>
12
+ <class>Anaraky_Gdrt_Model</class>
13
+ </gdrt>
14
+ </models>
15
+ <helpers>
16
+ <gdrt>
17
+ <class>Anaraky_Gdrt_Helper</class>
18
+ </gdrt>
19
+ </helpers>
20
+ <blocks>
21
+ <gdrt>
22
+ <class>Anaraky_Gdrt_Block</class>
23
+ </gdrt>
24
+ </blocks>
25
+ </global>
26
+
27
+ <default>
28
+ <gdrt>
29
+ <general>
30
+ <gdrt_enable>0</gdrt_enable>
31
+ </general>
32
+ <pages>
33
+ <home>cms/index/index</home>
34
+ <searchresults>catalogsearch/result/index</searchresults>
35
+ <category>catalog/category/view</category>
36
+ <product>catalog/product/view</product>
37
+ <cart>checkout/cart/index</cart>
38
+ <purchase>checkout/onepage/index</purchase>
39
+ </pages>
40
+ </gdrt>
41
+ </default>
42
+
43
+ <frontend>
44
+ <events>
45
+ <controller_action_layout_generate_xml_before>
46
+ <observers>
47
+ <gdrt_add_block>
48
+ <type>singleton</type>
49
+ <class>gdrt/observer</class>
50
+ <method>addGdrtBlock</method>
51
+ </gdrt_add_block>
52
+ </observers>
53
+ </controller_action_layout_generate_xml_before>
54
+ </events>
55
+ </frontend>
56
+ </config>
app/code/community/Anaraky/Gdrt/etc/system.xml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+
4
+ <tabs>
5
+ <gdrt_tab translate="label">
6
+ <label>Anaraky</label>
7
+ <sort_order>1</sort_order>
8
+ </gdrt_tab>
9
+ </tabs>
10
+
11
+ <sections>
12
+ <gdrt translate="label">
13
+ <label>GDRT Settings</label>
14
+ <tab>gdrt_tab</tab>
15
+ <sort_order>1</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <!-- general settings of the Google Dinamic Remarketing Tag -->
21
+ <general translate="label">
22
+ <label>General settings</label>
23
+ <sort_order>1</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <fields>
28
+ <gdrt_enable translate="label">
29
+ <label>Enable Google Remarketing Tag</label>
30
+ <frontend_type>select</frontend_type>
31
+ <source_model>adminhtml/system_config_source_yesno</source_model>
32
+ <sort_order>1</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ </gdrt_enable>
37
+ <gc_id>
38
+ <label>google_conversion_id</label>
39
+ <frontend_type>text</frontend_type>
40
+ <depends>
41
+ <gdrt_enable>1</gdrt_enable>
42
+ </depends>
43
+ <sort_order>2</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </gc_id>
48
+ <gc_label>
49
+ <label>google_conversion_label</label>
50
+ <frontend_type>text</frontend_type>
51
+ <comment>
52
+ This field is optional
53
+ </comment>
54
+ <depends>
55
+ <gdrt_enable>1</gdrt_enable>
56
+ </depends>
57
+ <sort_order>3</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ </gc_label>
62
+ </fields>
63
+ </general>
64
+
65
+ <pages translate="label">
66
+ <label>Setting of pages</label>
67
+ <sort_order>2</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ <fields>
72
+ <home translate="label">
73
+ <label>Home</label>
74
+ <frontend_type>text</frontend_type>
75
+ <comment>
76
+ <![CDATA[Model name / Controller name / Action name<br/>
77
+ Action name is optional ]]>
78
+ </comment>
79
+ <sort_order>1</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ </home>
84
+ <searchresults translate="label">
85
+ <label>Search results</label>
86
+ <frontend_type>text</frontend_type>
87
+ <comment>
88
+ Structure is the same as in the previous field
89
+ </comment>
90
+ <sort_order>2</sort_order>
91
+ <show_in_default>1</show_in_default>
92
+ <show_in_website>1</show_in_website>
93
+ <show_in_store>1</show_in_store>
94
+ </searchresults>
95
+ <category translate="label">
96
+ <label>Category</label>
97
+ <frontend_type>text</frontend_type>
98
+ <comment>
99
+ Structure is the same as in the previous field
100
+ </comment>
101
+ <sort_order>3</sort_order>
102
+ <show_in_default>1</show_in_default>
103
+ <show_in_website>1</show_in_website>
104
+ <show_in_store>1</show_in_store>
105
+ </category>
106
+ <product translate="label">
107
+ <label>Product</label>
108
+ <frontend_type>text</frontend_type>
109
+ <comment>
110
+ Structure is the same as in the previous field
111
+ </comment>
112
+ <sort_order>4</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ </product>
117
+ <cart translate="label">
118
+ <label>Cart</label>
119
+ <frontend_type>text</frontend_type>
120
+ <comment>
121
+ Structure is the same as in the previous field
122
+ </comment>
123
+ <sort_order>5</sort_order>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>1</show_in_website>
126
+ <show_in_store>1</show_in_store>
127
+ </cart>
128
+ <purchase translate="label">
129
+ <label>Purchase</label>
130
+ <frontend_type>text</frontend_type>
131
+ <comment>
132
+ Structure is the same as in the previous field
133
+ </comment>
134
+ <sort_order>6</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ </purchase>
139
+ </fields>
140
+ </pages>
141
+ </groups>
142
+ </gdrt>
143
+ </sections>
144
+ </config>
app/etc/modules/Anaraky_Gdrt.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Anaraky_Gdrt>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Anaraky_Gdrt>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Anaraky_GDRT_1</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.gnu.org/licenses/gpl.html">GNU General Public License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Google Dynamic Remarketing Tag extension for Magento</summary>
10
+ <description>With this extension is simply and easy to integrate the Google Dynamic Remarketing Tag into Magento.</description>
11
+ <notes>First stable release</notes>
12
+ <authors><author><name>Vladas Tomkevicius</name><user>Neodan</user><email>neodann@gmail.com</email></author></authors>
13
+ <date>2013-08-05</date>
14
+ <time>19:03:41</time>
15
+ <contents><target name="magecommunity"><dir name="Anaraky"><dir name="Gdrt"><dir name="Block"><file name="Script.php" hash="0433df3dd69f65c2543b875d60afd84f"/></dir><dir name="Helper"><file name="Data.php" hash="e1dfad9d739c7c3bc6094abae0af01e7"/></dir><dir name="Model"><file name="Observer.php" hash="36f4dfb4171c670b867d881bde03305d"/></dir><dir name="etc"><file name="adminhtml.xml" hash="03a29217c242534e2f13fe79e5fb43c7"/><file name="config.xml" hash="e2d6b41fe02bbbc88988c88118bab75b"/><file name="system.xml" hash="acdf972eba3a3c42edb738158954779e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Anaraky_Gdrt.xml" hash="43fa98d76721559c9ca20636dcb6af61"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.1.0</min><max>1.7</max></package></required></dependencies>
18
+ </package>