celtic_gauniversal - Version 1.0.0

Version Notes

1.0.0 : first release

Download this release

Release Info

Developer Hirokazu Nishi
Extension celtic_gauniversal
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Celtic/Gauniversal/Block/Ecommerce.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Celtic_Gauniversal_Block_Ecommerce extends Mage_Core_Block_Template
3
+ {
4
+ public function getOrders($orderIds)
5
+ {
6
+ if (empty($orderIds) || !is_array($orderIds)) {
7
+ return;
8
+ }
9
+ $collection = Mage::getResourceModel('sales/order_collection')
10
+ ->addFieldToFilter('entity_id', array('in' => $orderIds))
11
+ ;
12
+ return $collection;
13
+ }
14
+
15
+ public function getOrderTag($order)
16
+ {
17
+ $tag = "
18
+ ga('ecommerce:addTransaction', {
19
+ 'id': '{$order->getIncrementId()}',
20
+ 'affiliation': '". Mage::app()->getStore()->getFrontendName(). "',
21
+ 'revenue': '{$order->getBaseGrandTotal()}',
22
+ 'shipping': '{$order->getBaseShippingAmount()}',
23
+ 'tax': '{$order->getBaseTaxAmount()}',
24
+ 'currency': '{$order->getBaseCurrencyCode()}'
25
+ });";
26
+
27
+ return $tag;
28
+ }
29
+
30
+ public function getOrderItemTag($item, $order)
31
+ {
32
+ $tag = "
33
+ ga('ecommerce:addItem', {
34
+ 'id': '{$order->getIncrementId()}',
35
+ 'name': '{$this->jsQuoteEscape($item->getName())}',
36
+ 'sku': '{$this->jsQuoteEscape($item->getSku())}',
37
+ 'category': '',
38
+ 'price': '{$item->getBasePrice()}',
39
+ 'quantity': '{$item->getQtyOrdered()}',
40
+ 'currency': '{$order->getBaseCurrencyCode()}'
41
+ });
42
+ ";
43
+
44
+ return $tag;
45
+ }
46
+ }
app/code/community/Celtic/Gauniversal/Block/Tag.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Celtic_Gauniversal_Block_Tag extends Mage_Core_Block_Template
3
+ {
4
+ public function getTrackingId()
5
+ {
6
+ return Mage::getStoreConfig('google/celticga/account');
7
+ }
8
+
9
+ public function getDomainName()
10
+ {
11
+ return Mage::getStoreConfig('google/celticga/domain');
12
+ }
13
+
14
+ public function isEnabled()
15
+ {
16
+ return Mage::getStoreConfig('google/celticga/enable');
17
+ }
18
+
19
+ public function getParam()
20
+ {
21
+ $param ='';
22
+ if(Mage::getStoreConfig('google/celticga/usecustom')) {
23
+ $param = "{
24
+ 'cookieDomain': '".Mage::getStoreConfig('google/celticga/cookiedomain')."',
25
+ 'cookieName': '".Mage::getStoreConfig('google/celticga/cookiename')."',
26
+ 'cookieExpires': ".Mage::getStoreConfig('google/celticga/cookieexpire')."
27
+ }";
28
+ } else {
29
+ $param = "'{$this->getDomainName()}'";
30
+ }
31
+
32
+ return $param;
33
+ }
34
+
35
+ public function getPageName() {
36
+ if (!$this->hasData('page_name')) {
37
+ $pageName = Mage::getSingleton('core/url')->escape($_SERVER['REQUEST_URI']);
38
+ $pageName = rtrim(str_replace('index/','',$pageName), '/');
39
+ $this->setPageName($pageName);
40
+ }
41
+ return $this->getData('page_name');
42
+ }
43
+
44
+ public function getAjaxPageTracking()
45
+ {
46
+ $baseUrl = preg_replace('/\/\?.*/', '', $this->getPageName());
47
+
48
+ return '
49
+
50
+ if(Ajax.Responders){
51
+ Ajax.Responders.register({
52
+ onComplete: function(response){
53
+ if(!response.url.include("progress") && !response.url.include("getAdditional")){
54
+ if(response.url.include("saveOrder")){
55
+ ga("send", "pageview", "'.$baseUrl.'"+ "/opc-review-placeOrderClicked");
56
+ }else if(accordion.currentSection){
57
+ ga("send", "pageview", "'.$baseUrl.'/"+ accordion.currentSection);
58
+ }
59
+ }
60
+ }
61
+ });
62
+ }
63
+ ';
64
+ }
65
+
66
+ }
app/code/community/Celtic/Gauniversal/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Celtic_Gauniversal_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
app/code/community/Celtic/Gauniversal/etc/adminhtml.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <celticga>
11
+ <title>Celtic GoogleAnalytics Universal</title>
12
+ <sort_order>50</sort_order>
13
+ </celticga>
14
+ </children>
15
+ </admin>
16
+ </resources>
17
+ </acl>
18
+ </config>
app/code/community/Celtic/Gauniversal/etc/config.xml ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Celtic_Gauniversal>
5
+ <version>1.0.0</version>
6
+ </Celtic_Gauniversal>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <celticga>
11
+ <class>Celtic_Gauniversal_Block</class>
12
+ </celticga>
13
+ </blocks>
14
+ <helpers>
15
+ <celticga>
16
+ <class>Celtic_Gauniversal_Helper</class>
17
+ </celticga>
18
+ </helpers>
19
+ </global>
20
+ <adminhtml>
21
+ <translate>
22
+ <modules>
23
+ <Celtic_Gauniversal>
24
+ <files>
25
+ <default>Celtic_Gauniversal.csv</default>
26
+ </files>
27
+ </Celtic_Gauniversal>
28
+ </modules>
29
+ </translate>
30
+ </adminhtml>
31
+ <frontend>
32
+ <layout>
33
+ <updates>
34
+ <celticga>
35
+ <file>celtic_gauniversal.xml</file>
36
+ </celticga>
37
+ </updates>
38
+ </layout>
39
+ <events>
40
+ <checkout_onepage_controller_success_action>
41
+ <observers>
42
+ <celticga>
43
+ <class>Celtic_Gauniversal_Model_Observer</class>
44
+ <method>onCheckoutSuccess</method>
45
+ </celticga>
46
+ </observers>
47
+ </checkout_onepage_controller_success_action>
48
+ <checkout_multishipping_controller_success_action>
49
+ <observers>
50
+ <celticga>
51
+ <class>Celtic_Gauniversal_Model_Observer</class>
52
+ <method>onCheckoutSuccess</method>
53
+ </celticga>
54
+ </observers>
55
+ </checkout_multishipping_controller_success_action>
56
+ </events>
57
+ </frontend>
58
+ <default>
59
+ <google>
60
+ <celticga>
61
+ <enable>0</enable>
62
+ <cookieexpire>63072000</cookieexpire>
63
+ <domain>auto</domain>
64
+ <usecustom>0</usecustom>
65
+ </celticga>
66
+ </google>
67
+ </default>
68
+ </config>
app/code/community/Celtic/Gauniversal/etc/system.xml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <sections>
4
+ <google translate="label">
5
+ <groups>
6
+ <celticga translate="label">
7
+ <label>Google Universal Analytics</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>1000</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <enable translate="label" module="celticga">
15
+ <label>Enable</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </enable>
23
+ <account translate="label" module="celticga">
24
+ <label>Tracking Id</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>2</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </account>
31
+ <usecustom translate="label" module="celticga">
32
+ <label>Use custom cookie</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
+ <sort_order>3</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>1</show_in_store>
39
+ </usecustom>
40
+ <domain translate="label" module="celticga">
41
+ <label>Domain name</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>4</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
+ <depends><usecustom>0</usecustom></depends>
48
+ </domain>
49
+ <cookiedomain translate="label" module="celticga">
50
+ <label>Cookie Domain name</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>5</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ <depends><usecustom>1</usecustom></depends>
57
+ </cookiedomain>
58
+ <cookiename translate="label" module="celticga">
59
+ <label>Cookie name</label>
60
+ <frontend_type>text</frontend_type>
61
+ <sort_order>6</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ <depends><usecustom>1</usecustom></depends>
66
+ </cookiename>
67
+ <cookieexpire translate="label" module="celticga">
68
+ <label>Cookie expire</label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>7</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ <depends><usecustom>1</usecustom></depends>
75
+ </cookieexpire>
76
+ </fields>
77
+ </celticga>
78
+ </groups>
79
+ </google>
80
+ </sections>
81
+ </config>
app/design/frontend/base/default/layout/celtic_gauniversal.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <block type="celticga/tag" name="google_analytics" as="google_analytics" template="celtic_gauniversal/tag.phtml" />
6
+ </reference>
7
+ <reference name="after_body_start">
8
+ <action method="unsetChild"><name>google_analytics</name></action>
9
+ </reference>
10
+ <reference name="before_body_end">
11
+ <action method="unsetChild"><name>google_analytics</name></action>
12
+ </reference>
13
+ </default>
14
+ <checkout_onepage_success>
15
+ <reference name="before_body_end">
16
+ <block type="celticga/ecommerce" name="celticga_ecommerce" template="celtic_gauniversal/ecommerce.phtml" />
17
+ </reference>
18
+ </checkout_onepage_success>
19
+ <checkout_multishipping_success>
20
+ <reference name="before_body_end">
21
+ <block type="celticga/ecommerce" name="celticga_ecommerce" template="celtic_gauniversal/ecommerce.phtml" />
22
+ </reference>
23
+ </checkout_multishipping_success>
24
+ </layout>
app/design/frontend/base/default/template/celtic_gauniversal/ecommerce.phtml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ ga('require', 'ecommerce', 'ecommerce.js');
3
+ <?php $orderIds = $this->getOrderIds()?>
4
+ <?php $orders = $this->getOrders($orderIds);?>
5
+ <?php foreach($orders as $order): ?>
6
+ <?php echo $this->getOrderTag($order);?>
7
+ <?php foreach($order->getAllVisibleItems() as $item): ?>
8
+ <?php echo $this->getOrderItemTag($item, $order);?>
9
+ <?php endforeach;?>
10
+ <?php endforeach;?>
11
+ ga('ecommerce:send');
12
+ </script>
app/design/frontend/base/default/template/celtic_gauniversal/tag.phtml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if($this->isEnabled()):?>
2
+ <script type="text/javascript">
3
+ //<!CDATA[[
4
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
5
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
6
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
7
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
8
+
9
+ ga('create', '<?php echo $this->getTrackingId()?>', <?php echo $this->getParam()?>);
10
+ ga('send', 'pageview');
11
+ <?php echo $this->getAjaxPageTracking();?>
12
+ //]]>
13
+ </script>
14
+ <?php endif;?>
app/etc/modules/Celtic_Gauniversal.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Celtic_Gauniversal>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Celtic_Gauniversal>
8
+ </modules>
9
+ </config>
app/locale/ja_JP/Celtic_Gauniversal.csv ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ "Celtic GoogleAnalytics Universal","ケルトコーポレーション Googleユニバーサルアナリティクス"
2
+ "Google Universal Analytics","Googleユニバーサルアナリティクス"
3
+ "Enable","有効"
4
+ "Tracking Id","トラッキングIDの"
5
+ "Use custom cookie","カスタムCookieを使用"
6
+ "Domain name","計測対象ドメイン名"
7
+ "Cookie Domain name","Cookieドメイン名"
8
+ "Cookie name","Cookie名"
9
+ "Cookie expire","Cookie有効期限"
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>celtic_gauniversal</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL V3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Insert Google Universal Analytics tracking codes into your Magento</summary>
10
+ <description>Insert Google Universal Analytics tracking codes into your Magento</description>
11
+ <notes>1.0.0 : first release</notes>
12
+ <authors><author><name>Hirokazu Nishi</name><user>hirokazu_n</user><email>nishi@principle-works.jp</email></author></authors>
13
+ <date>2014-03-06</date>
14
+ <time>04:54:06</time>
15
+ <contents><target name="magecommunity"><dir name="Celtic"><dir name="Gauniversal"><dir name="Block"><file name="Ecommerce.php" hash="911e7973f46f1a65dd092f7a57a56ef4"/><file name="Tag.php" hash="c835727cd006103bc17d364686b93b4e"/></dir><dir name="Helper"><file name="Data.php" hash="bb5efc36937fcbaf07f20df7da38a3a4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="f4c2465ba095f4dad3b1d45160a7bb4b"/><file name="config.xml" hash="3b22e0dd25bed3f2e519a87d192ed471"/><file name="system.xml" hash="b93ad4e67ac2c31e5ca9b9f56d0a5982"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="celtic_gauniversal.xml" hash="84b11a6dd633719e7515644323c6e709"/></dir><dir name="template"><dir name="celtic_gauniversal"><file name="ecommerce.phtml" hash="de44f56d6f5040b4cd2dbf5bb6387017"/><file name="tag.phtml" hash="123a9b7f11f05bc93e21662baa9d0d8b"/></dir></dir></dir></dir></dir></target><target name="magelocale"><dir name="ja_JP"><file name="Celtic_Gauniversal.csv" hash="00d07d45067f7abef43a72745d470754"/></dir></target><target name="mageetc"><dir name="modules"><file name="Celtic_Gauniversal.xml" hash="3e9b9db09f64cc403666852c98b14714"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>5.5.99</max></php></required></dependencies>
18
+ </package>