Version Notes
A simple extension to give you valuable insight into how many visits you’re getting to 404 Not Found URLs.
Download this release
Release Info
Developer | Demac Media |
Extension | Demac_Analytics |
Version | 0.1.0 |
Comparing to | |
See all releases |
Version 0.1.0
app/code/local/Demac/Analytics/Block/Ga.php
ADDED
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_GoogleAnalytics
|
23 |
+
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
|
28 |
+
/**
|
29 |
+
* GoogleAnalitics Page Block
|
30 |
+
*
|
31 |
+
* @category Mage
|
32 |
+
* @package Mage_GoogleAnalytics
|
33 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
34 |
+
*/
|
35 |
+
class Demac_Analytics_Block_Ga extends Mage_GoogleAnalytics_Block_Ga
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* @deprecated after 1.4.1.1
|
39 |
+
* @see self::_getOrdersTrackingCode()
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public function getQuoteOrdersHtml()
|
43 |
+
{
|
44 |
+
return '';
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @deprecated after 1.4.1.1
|
49 |
+
* self::_getOrdersTrackingCode()
|
50 |
+
* @return string
|
51 |
+
*/
|
52 |
+
public function getOrderHtml()
|
53 |
+
{
|
54 |
+
return '';
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @deprecated after 1.4.1.1
|
59 |
+
* @see _toHtml()
|
60 |
+
* @return string
|
61 |
+
*/
|
62 |
+
public function getAccount()
|
63 |
+
{
|
64 |
+
return '';
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Get a specific page name (may be customized via layout)
|
69 |
+
*
|
70 |
+
* @return string|null
|
71 |
+
*/
|
72 |
+
public function getPageName()
|
73 |
+
{
|
74 |
+
return $this->_getData('page_name');
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Render regular page tracking javascript code
|
79 |
+
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
|
80 |
+
*
|
81 |
+
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview
|
82 |
+
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gaq.html
|
83 |
+
* @param string $accountId
|
84 |
+
* @return string
|
85 |
+
*/
|
86 |
+
protected function _getPageTrackingCode($accountId)
|
87 |
+
{
|
88 |
+
$action = Mage::app()->getRequest()->getActionName();
|
89 |
+
if($action == 'noRoute'){
|
90 |
+
$pageName = "'/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
|
91 |
+
return "
|
92 |
+
_gaq.push(['_setAccount', '{$this->jsQuoteEscape($accountId)}']);
|
93 |
+
_gaq.push(['_trackPageview', {$pageName}]);
|
94 |
+
";
|
95 |
+
|
96 |
+
}else {
|
97 |
+
$pageName = trim($this->getPageName());
|
98 |
+
$optPageURL = '';
|
99 |
+
if ($pageName && preg_match('/^\/.*/i', $pageName)) {
|
100 |
+
$optPageURL = ", '{$this->jsQuoteEscape($pageName)}'";
|
101 |
+
}
|
102 |
+
return "
|
103 |
+
_gaq.push(['_setAccount', '{$this->jsQuoteEscape($accountId)}']);
|
104 |
+
_gaq.push(['_trackPageview'{$optPageURL}]);
|
105 |
+
";
|
106 |
+
|
107 |
+
}
|
108 |
+
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Render information about specified orders and their items
|
113 |
+
*
|
114 |
+
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
|
115 |
+
* @return string
|
116 |
+
*/
|
117 |
+
protected function _getOrdersTrackingCode()
|
118 |
+
{
|
119 |
+
$orderIds = $this->getOrderIds();
|
120 |
+
if (empty($orderIds) || !is_array($orderIds)) {
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
$collection = Mage::getResourceModel('sales/order_collection')
|
124 |
+
->addFieldToFilter('entity_id', array('in' => $orderIds))
|
125 |
+
;
|
126 |
+
$result = array();
|
127 |
+
foreach ($collection as $order) {
|
128 |
+
if ($order->getIsVirtual()) {
|
129 |
+
$address = $order->getBillingAddress();
|
130 |
+
} else {
|
131 |
+
$address = $order->getShippingAddress();
|
132 |
+
}
|
133 |
+
$result[] = sprintf("_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']);",
|
134 |
+
$order->getIncrementId(), $this->jsQuoteEscape(Mage::app()->getStore()->getFrontendName()), $order->getBaseGrandTotal(),
|
135 |
+
$order->getBaseTaxAmount(), $order->getBaseShippingAmount(),
|
136 |
+
$this->jsQuoteEscape($address->getCity()),
|
137 |
+
$this->jsQuoteEscape($address->getRegion()),
|
138 |
+
$this->jsQuoteEscape($address->getCountry())
|
139 |
+
);
|
140 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
141 |
+
$result[] = sprintf("_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']);",
|
142 |
+
$order->getIncrementId(),
|
143 |
+
$this->jsQuoteEscape($item->getSku()), $this->jsQuoteEscape($item->getName()),
|
144 |
+
null, // there is no "category" defined for the order item
|
145 |
+
$item->getBasePrice(), $item->getQtyOrdered()
|
146 |
+
);
|
147 |
+
}
|
148 |
+
$result[] = "_gaq.push(['_trackTrans']);";
|
149 |
+
}
|
150 |
+
return implode("\n", $result);
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Render GA tracking scripts
|
155 |
+
*
|
156 |
+
* @return string
|
157 |
+
*/
|
158 |
+
protected function _toHtml()
|
159 |
+
{
|
160 |
+
if (!Mage::helper('googleanalytics')->isGoogleAnalyticsAvailable()) {
|
161 |
+
return '';
|
162 |
+
}
|
163 |
+
$accountId = Mage::getStoreConfig(Mage_GoogleAnalytics_Helper_Data::XML_PATH_ACCOUNT);
|
164 |
+
return '
|
165 |
+
<!-- BEGIN GOOGLE ANALYTICS CODE -->
|
166 |
+
<script type="text/javascript">
|
167 |
+
//<![CDATA[
|
168 |
+
(function() {
|
169 |
+
var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
|
170 |
+
ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
|
171 |
+
(document.getElementsByTagName(\'head\')[0] || document.getElementsByTagName(\'body\')[0]).appendChild(ga);
|
172 |
+
})();
|
173 |
+
|
174 |
+
var _gaq = _gaq || [];
|
175 |
+
' . $this->_getPageTrackingCode($accountId) . '
|
176 |
+
' . $this->_getOrdersTrackingCode() . '
|
177 |
+
//]]>
|
178 |
+
</script>
|
179 |
+
<!-- END GOOGLE ANALYTICS CODE -->';
|
180 |
+
}
|
181 |
+
}
|
app/code/local/Demac/Analytics/etc/config.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<modules>
|
5 |
+
<Demac_Analytics>
|
6 |
+
<version>0.1.0</version>
|
7 |
+
</Demac_Analytics>
|
8 |
+
</modules>
|
9 |
+
<global>
|
10 |
+
<blocks>
|
11 |
+
<googleanalytics>
|
12 |
+
<rewrite>
|
13 |
+
<ga>Demac_Analytics_Block_Ga</ga>
|
14 |
+
</rewrite>
|
15 |
+
</googleanalytics>
|
16 |
+
</blocks>
|
17 |
+
</global>
|
18 |
+
</config>
|
app/etc/modules/Demac_Analytics.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Demac_Analytics>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>local</codePool>
|
7 |
+
</Demac_Analytics>
|
8 |
+
</modules>
|
9 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Demac_Analytics</name>
|
4 |
+
<version>0.1.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>404 Not Found Request Tracking for Google Analytics.
|
10 |
+

|
11 |
+
A simple extension to give you valuable insight into how many visits you’re getting to 404 Not Found URLs.</summary>
|
12 |
+
<description>Magento by default gives you a configuration variable that allows you to set which CMS page is used for 404 Not Found requests. This is an awesome way to provide useful information to a visitor who can’t find what they are looking for or even for old/broken URLs.
|
13 |
+

|
14 |
+
Recently we were looking through the analytics for a few of our sites and we realized that we don’t even know how often people are hitting 404′s. Not only how many 404′s, but what URLs were they requesting that caused them to hit a 404?
|
15 |
+

|
16 |
+
To solve this, we extended Analytics module in the Magento core to provide a 301 redirect to our actual 404 CMS Page, instead of letting Magento simply load the 404 page with the requested URL as the pageview.</description>
|
17 |
+
<notes>A simple extension to give you valuable insight into how many visits you’re getting to 404 Not Found URLs.</notes>
|
18 |
+
<authors><author><name>Demac Media</name><user>demacmedia</user><email>mbertulli@demacmedia.com</email></author></authors>
|
19 |
+
<date>2011-11-10</date>
|
20 |
+
<time>20:54:17</time>
|
21 |
+
<contents><target name="magelocal"><dir name="Demac"><dir name="Analytics"><dir name="Block"><file name="Ga.php" hash="134d0c1ba80abf5d48a1959c09ce28fe"/></dir><dir name="etc"><file name="config.xml" hash="0cf2d9f6292ff7e139671bbfed5eeec5"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Demac_Analytics.xml" hash="652daf3148de849b5293b6ea6f52ff63"/></dir></target></contents>
|
22 |
+
<compatible/>
|
23 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Demac_All</name><channel>community</channel><min>5.2.0</min><max>6.0.0</max></package></required></dependencies>
|
24 |
+
</package>
|