reckess-io-trafficsource - Version 1.0.0.0

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 reckess-io-trafficsource
Version 1.0.0.0
Comparing to
See all releases


Version 1.0.0.0

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.swp ADDED
Binary file
app/code/community/Reckless/TrafficSource/Model/Observer.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $utmzCookie = '252594521.1399922653.21.2.utmcsr=ExactTarget|utmccn=10May2014-BabyNursery-UK|utmcmd=Email';
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
+ $utmzCookie = '252594521.1399922653.21.2.utmcsr=ExactTarget|utmccn=10May2014-BabyNursery-UK|utmcmd=Email';
72
+ Mage::log($utmzCookie);
73
+
74
+ if ($utmzCookie) {
75
+ $utmzParams = array();
76
+ parse_str(
77
+ str_replace(
78
+ '|',
79
+ '&',
80
+ substr(
81
+ $utmzCookie,
82
+ strpos($utmzCookie, 'utm')
83
+ )
84
+ ),
85
+ $utmzParams
86
+ );
87
+
88
+ $order->setData(
89
+ 'rkl_utm_source',
90
+ isset(
91
+ $utmzParams['utmcsr']
92
+ ) ? $utmzParams['utmcsr'] : ''
93
+ );
94
+
95
+ $order->setData(
96
+ 'rkl_utm_medium',
97
+ isset(
98
+ $utmzParams['utmcmd']
99
+ ) ? $utmzParams['utmcmd'] : ''
100
+ );
101
+
102
+ $order->setData(
103
+ 'rkl_utm_term',
104
+ isset(
105
+ $utmzParams['utmctr']
106
+ ) ? $utmzParams['utmctr'] : ''
107
+ );
108
+
109
+ $order->setData(
110
+ 'rkl_utm_content',
111
+ isset(
112
+ $utmzParams['utmcct']
113
+ ) ? $utmzParams['utmcct'] : ''
114
+ );
115
+
116
+ $order->setData(
117
+ 'rkl_utm_campaign',
118
+ isset(
119
+ $utmzParams['utmccn']
120
+ ) ? $utmzParams['utmccn'] : ''
121
+ );
122
+ }
123
+ return $this;
124
+ }
125
+ }
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>reckess-io-trafficsource</name>
4
+ <version>1.0.0.0</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-13</date>
22
+ <time>08:37:10</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><file name=".Observer.php.swp" hash="dc6f8be292cdf9c944658882121abc65"/></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="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="Reckless_TrafficSource.xml" hash="7666b2e22e361240527cd9b3612ab428"/></dir></dir></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies><required><php><min>5.2.0</min><max>5.4.0</max></php></required></dependencies>
26
+ </package>