Recklessio_Trafficsource - Version 1.0.2

Version Notes

- Store google campaigns customer origin data in the placed orders.
- Store customer referral URL in the placed orders.
- Enhanced sales order grid to allow customer to filter by the new data.

Download this release

Release Info

Developer Reckless
Extension Recklessio_Trafficsource
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

app/code/community/Reckless/TrafficSource/Block/Adminhtml/Order/Grid.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Reckless_TrafficSource_Block_Adminhtml_Order_Grid
4
+ *
5
+ * @uses Mage_Adminhtml_Block_Widget_Grid
6
+ * @package
7
+ * @version $id$
8
+ * @link www.reckless.io
9
+ * @author JC <hello@reckless.io>
10
+ */
11
+ class Reckless_TrafficSource_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
12
+ {
13
+ protected function _prepareColumns()
14
+ {
15
+ $this->addColumnAfter(
16
+ 'rkl_utm_campaign',
17
+ array(
18
+ 'header'=> Mage::helper('sales')->__('Utm Campaign'),
19
+ 'width' => '80px',
20
+ 'type' => 'text',
21
+ 'index' => 'rkl_utm_campaign',
22
+ ),
23
+ 'grand_total'
24
+ );
25
+ $this->addColumnAfter(
26
+ 'rkl_web_source',
27
+ array(
28
+ 'header'=> Mage::helper('sales')->__('Traffic Source'),
29
+ 'width' => '80px',
30
+ 'type' => 'text',
31
+ 'index' => 'rkl_web_source',
32
+ ),
33
+ 'grand_total'
34
+ );
35
+ parent::_prepareColumns();
36
+
37
+
38
+ return $this;
39
+ }
40
+ }
app/code/community/Reckless/TrafficSource/Model/Observer.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Reckless_TrafficSource_Model_Observer
4
+ *
5
+ * @uses Mage_Core_Model_Abstract
6
+ * @package
7
+ * @version $id$
8
+ * @link www.reckless.io
9
+ * @author JC <hello@reckless.io>
10
+ */
11
+ class Reckless_TrafficSource_Model_Observer extends Mage_Core_Model_Abstract
12
+ {
13
+ /**
14
+ * Predispatch Controller
15
+ * Store referer url in session to save the user's origin when placing an order.
16
+ *
17
+ * @param Varien_Object $observer
18
+ * @return $this
19
+ */
20
+ public function controllerActionPredispatch($observer)
21
+ {
22
+ $referer = parse_url(Mage::app()->getFrontController()->getRequest()->getServer('HTTP_REFERER'), PHP_URL_HOST);
23
+ $current = parse_url(Mage::helper('core/url')->getCurrentUrl(), PHP_URL_HOST);
24
+
25
+ if ($referer && $referer != $current) {
26
+ $customerSession = Mage::getSingleton('customer/session');
27
+ $customerSession->setData(
28
+ 'rkl_web_source',
29
+ $referer
30
+ );
31
+ }
32
+ $utmzCookie = Mage::getModel('core/cookie')->get('__utmz');
33
+
34
+ if ($utmzCookie) {
35
+ $utmzParams = array();
36
+ parse_str(
37
+ str_replace(
38
+ '|',
39
+ '&',
40
+ substr(
41
+ $utmzCookie,
42
+ strpos($utmzCookie, 'utm')
43
+ )
44
+ ),
45
+ $utmzParams
46
+ );
47
+ Mage::log($utmzParams);
48
+ }
49
+ return $this;
50
+ }
51
+
52
+
53
+ /**
54
+ * Observer: salesOrderSaveBefore
55
+ * Save the referer url and the google campaigns data in the order.
56
+ *
57
+ * @param Varien_Object $observer
58
+ * @return $this
59
+ */
60
+ public function salesOrderSaveBefore($observer)
61
+ {
62
+
63
+ $order = $observer->getEvent()->getOrder();
64
+ $utmzCookie = Mage::getModel('core/cookie')->get('__utmz');
65
+ $customerSession = Mage::getSingleton('customer/session');
66
+
67
+ $order->setData(
68
+ 'rkl_web_source',
69
+ $customerSession->getData('rkl_web_source')
70
+ );
71
+
72
+ if ($utmzCookie) {
73
+ $utmzParams = array();
74
+ parse_str(
75
+ str_replace(
76
+ '|',
77
+ '&',
78
+ substr(
79
+ $utmzCookie,
80
+ strpos($utmzCookie, 'utm')
81
+ )
82
+ ),
83
+ $utmzParams
84
+ );
85
+
86
+ $order->setData(
87
+ 'rkl_utm_source',
88
+ isset(
89
+ $utmzParams['utmcsr']
90
+ ) ? $utmzParams['utmcsr'] : ''
91
+ );
92
+
93
+ $order->setData(
94
+ 'rkl_utm_medium',
95
+ isset(
96
+ $utmzParams['utmcmd']
97
+ ) ? $utmzParams['utmcmd'] : ''
98
+ );
99
+
100
+ $order->setData(
101
+ 'rkl_utm_term',
102
+ isset(
103
+ $utmzParams['utmctr']
104
+ ) ? $utmzParams['utmctr'] : ''
105
+ );
106
+
107
+ $order->setData(
108
+ 'rkl_utm_content',
109
+ isset(
110
+ $utmzParams['utmcct']
111
+ ) ? $utmzParams['utmcct'] : ''
112
+ );
113
+
114
+ $order->setData(
115
+ 'rkl_utm_campaign',
116
+ isset(
117
+ $utmzParams['utmccn']
118
+ ) ? $utmzParams['utmccn'] : ''
119
+ );
120
+ }
121
+ return $this;
122
+ }
123
+ }
app/code/community/Reckless/TrafficSource/Model/Resource/Setup.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Reckless_TrafficSource_Model_Resource_Setup
4
+ *
5
+ * @uses Mage_Sales_Model_Resource_Setup
6
+ * @package
7
+ * @version $id$
8
+ * @link www.reckless.io
9
+ * @author JC <hello@reckless.io>
10
+ */
11
+ class Reckless_TrafficSource_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup
12
+ {
13
+ }
app/code/community/Reckless/TrafficSource/etc/config.xml ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Reckless_TrafficSource>
5
+ <version>1.0.0.0</version>
6
+ </Reckless_TrafficSource>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <Reckless_TrafficSource>
11
+ <class>Reckless_TrafficSource_Model</class>
12
+ <resourceModel>Reckless_TrafficSource_resource</resourceModel>
13
+ </Reckless_TrafficSource>
14
+ </models>
15
+ <blocks>
16
+ <adminhtml>
17
+ <rewrite>
18
+ <sales_order_grid>Reckless_TrafficSource_Block_Adminhtml_Order_Grid</sales_order_grid>
19
+ </rewrite>
20
+ </adminhtml>
21
+ </blocks>
22
+ <resources>
23
+ <reckless_trafficsource_setup>
24
+ <setup>
25
+ <module>Reckless_TrafficSource</module>
26
+ <class>Reckless_TrafficSource_Model_Resource_Setup</class>
27
+ </setup>
28
+ </reckless_trafficsource_setup>
29
+ <connection>
30
+ <use>core_setup</use>
31
+ </connection>
32
+ <Reckless_TrafficSource_write>
33
+ <connection>
34
+ <use>core_write</use>
35
+ </connection>
36
+ </Reckless_TrafficSource_write>
37
+ <Reckless_TrafficSource_read>
38
+ <connection>
39
+ <use>core_read</use>
40
+ </connection>
41
+ </Reckless_TrafficSource_read>
42
+ </resources>
43
+ </global>
44
+ <frontend>
45
+ <events>
46
+ <controller_action_predispatch>
47
+ <observers>
48
+ <Reckless_TrafficSource>
49
+ <type>singleton</type>
50
+ <class>Reckless_TrafficSource/observer</class>
51
+ <method>controllerActionPredispatch</method>
52
+ </Reckless_TrafficSource>
53
+ </observers>
54
+ </controller_action_predispatch>
55
+ <sales_order_save_before>
56
+ <observers>
57
+ <Reckless_TrafficSource>
58
+ <type>singleton</type>
59
+ <class>Reckless_TrafficSource/observer</class>
60
+ <method>salesOrderSaveBefore</method>
61
+ </Reckless_TrafficSource>
62
+ </observers>
63
+ </sales_order_save_before>
64
+ </events>
65
+ </frontend>
66
+ </config>
app/code/community/Reckless/TrafficSource/sql/reckless_trafficsource_setup/install-1.0.0.0.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+ /* @var $installer Mage_Sales_Model_Resource_Setup */
4
+
5
+ $installer->startSetup();
6
+
7
+ $data = array(
8
+ 'type' => 'varchar',
9
+ 'label' => 'web_source',
10
+ 'grid' => true,
11
+ 'input' => 'text',
12
+ 'default' => '',
13
+ 'sort_order' => 890,
14
+ 'position' => 890,
15
+ 'user_defined' => 1,
16
+ 'default' => null,
17
+ 'required' => 0
18
+ );
19
+
20
+ $installer->addAttribute('order', 'rkl_web_source', $data);
21
+
22
+ // Create index to enhance the search speed on the grid
23
+ $installer->getConnection()->addIndex(
24
+ $installer->getTable('sales/order_grid'),
25
+ $installer->getIdxName('sales/order_grid', array('rkl_web_source')),
26
+ array('rkl_web_source')
27
+ );
28
+
29
+ $data = array(
30
+ 'type' => 'varchar',
31
+ 'label' => 'utmz_utmcct',
32
+ 'grid' => true,
33
+ 'input' => 'text',
34
+ 'default' => '',
35
+ 'sort_order' => 940,
36
+ 'position' => 940,
37
+ 'user_defined' => 1,
38
+ 'default' => null,
39
+ 'required' => 0
40
+ );
41
+
42
+ $installer->addAttribute('order', 'rkl_utm_campaign', $data);
43
+
44
+ // Create index to enhance the search speed on the grid
45
+ $installer->getConnection()->addIndex(
46
+ $installer->getTable('sales/order_grid'),
47
+ $installer->getIdxName('sales/order_grid', array('rkl_utm_campaign')),
48
+ array('rkl_utm_campaign')
49
+ );
50
+
51
+ $data = array(
52
+ 'type' => 'varchar',
53
+ 'label' => 'utmz_utmcsr',
54
+ 'input' => 'text',
55
+ 'default' => '',
56
+ 'sort_order' => 900,
57
+ 'position' => 900,
58
+ 'user_defined' => 1,
59
+ 'default' => null,
60
+ 'required' => 0
61
+ );
62
+
63
+ $installer->addAttribute('order', 'rkl_utm_source', $data);
64
+
65
+ $data = array(
66
+ 'type' => 'varchar',
67
+ 'label' => 'utmz_utmcmd',
68
+ 'input' => 'text',
69
+ 'default' => '',
70
+ 'sort_order' => 910,
71
+ 'position' => 910,
72
+ 'user_defined' => 1,
73
+ 'default' => null,
74
+ 'required' => 0
75
+ );
76
+
77
+ $installer->addAttribute('order', 'rkl_utm_medium', $data);
78
+
79
+ $data = array(
80
+ 'type' => 'varchar',
81
+ 'label' => 'utmz_utmccn',
82
+ 'input' => 'text',
83
+ 'default' => '',
84
+ 'sort_order' => 920,
85
+ 'position' => 920,
86
+ 'user_defined' => 1,
87
+ 'default' => null,
88
+ 'required' => 0
89
+ );
90
+
91
+ $installer->addAttribute('order', 'rkl_utm_term', $data);
92
+
93
+ $data = array(
94
+ 'type' => 'varchar',
95
+ 'label' => 'utmz_utmctr',
96
+ 'input' => 'text',
97
+ 'default' => '',
98
+ 'sort_order' => 930,
99
+ 'position' => 930,
100
+ 'user_defined' => 1,
101
+ 'default' => null,
102
+ 'required' => 0
103
+ );
104
+
105
+ $installer->addAttribute('order', 'rkl_utm_content', $data);
106
+
107
+
108
+ $installer->endSetup();
app/etc/modules/Reckless_TrafficSource.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * PHP Unit test suite for Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category EcomDev
14
+ * @package EcomDev_PHPUnit
15
+ * @copyright Copyright (c) 2013 EcomDev B.V. (http://www.ecomdev.org)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ * @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <Reckless_TrafficSource>
23
+ <codePool>community</codePool>
24
+ <active>true</active>
25
+ <depends>
26
+ <Mage_Sales/>
27
+ </depends>
28
+ </Reckless_TrafficSource>
29
+ </modules>
30
+ </config>
package.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Recklessio_Trafficsource</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Magento Traffic Source Tracker</summary>
10
+ <description>Magento modules to enhance reckless.io functionalities and provide more powerful information.&#xD;
11
+ &#xD;
12
+ This Magento module captures the source of every user visiting your website and saves the source when an order is placed. The admin user can then filter the source for every sales order in the Magento backend for further segmentation analysis.&#xD;
13
+ &#xD;
14
+ There is a different commercial version of the module, which will directly sync more information to Reckless.io big data servers for powerful analysis.&#xD;
15
+ &#xD;
16
+ Please note: for commercial sites we strongly recommend you get in touch with the development team at hello@reckless.io to ensure you make the best of the features or custom build yours, as well as access to our support team should you experience any problems.</description>
17
+ <notes>- Store google campaigns customer origin data in the placed orders.&#xD;
18
+ - Store customer referral URL in the placed orders.&#xD;
19
+ - Enhanced sales order grid to allow customer to filter by the new data.</notes>
20
+ <authors><author><name>Reckless</name><user>recklessio</user><email>hello@reckless.io</email></author></authors>
21
+ <date>2014-05-21</date>
22
+ <time>10:53:23</time>
23
+ <contents><target name="magecommunity"><dir name="Reckless"><dir name="TrafficSource"><dir name="Block"><dir name="Adminhtml"><dir name="Order"><file name="Grid.php" hash="a152310d618c01a9c1a9cc47f9d84994"/></dir></dir></dir><dir name="Model"><file name="Observer.php" hash="12681feae07fcab8c16aea0fc8af21b0"/><dir name="Resource"><file name="Setup.php" hash="dde10cce215c0971a3a3ee2d53d2a4b0"/></dir></dir><dir name="etc"><file name="config.xml" hash="5540371451d1c31e5aa3c4511812b6f0"/></dir><dir name="sql"><dir name="reckless_trafficsource_setup"><file name="install-1.0.0.0.php" hash="17ab95393b085bac2d7bb59c88b7c8a3"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Reckless_TrafficSource.xml" hash="7666b2e22e361240527cd9b3612ab428"/></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>comminuity</channel><min>1.0.0.0</min><max>1.9</max></package></required></dependencies>
26
+ </package>