Creare_Abtesting - Version 0.1.0

Version Notes

First Release

Download this release

Release Info

Developer Robert Kent
Extension Creare_Abtesting
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Creare/Abtesting/Helper/Data.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Creare_Abtesting_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ public function getCode()
6
+ {
7
+ $cookie = Mage::getModel('core/cookie')->get('abtesting');
8
+ $session = Mage::getSingleton('core/session')->getAbTest();
9
+
10
+ if(!$cookie){
11
+ if($session){
12
+ if($session == 'a'){
13
+ return Mage::getStoreConfig('abtesting/accounts/acode');
14
+ } else {
15
+ return Mage::getStoreConfig('abtesting/accounts/bcode');
16
+ }
17
+ }
18
+ } else {
19
+ if($cookie == 'a'){
20
+ return Mage::getStoreConfig('abtesting/accounts/acode');
21
+ } else {
22
+ return Mage::getStoreConfig('abtesting/accounts/bcode');
23
+ }
24
+ }
25
+ }
26
+ }
app/code/local/Creare/Abtesting/Model/Observer.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Creare_Abtesting_Model_Observer
4
+ {
5
+ public function removeAbSession()
6
+ {
7
+ Mage::getSingleton('core/session')->setAbTesting('');
8
+ }
9
+
10
+ public function removeTempSession()
11
+ {
12
+ Mage::getSingleton('core/session')->setAbTest('');
13
+ }
14
+ }
app/code/local/Creare/Abtesting/Model/Package.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Creare_Abtesting_Model_Package extends Mage_Core_Model_Design_Package
4
+ {
5
+ public function getTheme($type)
6
+ {
7
+ if (empty($this->_theme[$type])) {
8
+ $this->_theme[$type] = Mage::getStoreConfig('design/theme/'.$type, $this->getStore());
9
+ if ($type!=='default' && empty($this->_theme[$type])) {
10
+ $this->_theme[$type] = $this->getTheme('default');
11
+ if (empty($this->_theme[$type])) {
12
+ $this->_theme[$type] = self::DEFAULT_THEME;
13
+ }
14
+
15
+ // "locale", "layout", "template"
16
+ }
17
+ }
18
+
19
+ // + "default", "skin"
20
+
21
+ // set exception value for theme, if defined in config
22
+ $customThemeType = $this->_checkUserAgentAgainstRegexps("design/theme/{$type}_ua_regexp");
23
+ if ($customThemeType) {
24
+ $this->_theme[$type] = $customThemeType;
25
+ }
26
+
27
+ /* Our cookie code */
28
+
29
+ $cookie = Mage::getModel('core/cookie')->get('abtesting');
30
+ $temp = Mage::getSingleton('core/session')->getAbTesting();
31
+
32
+ if(Mage::getStoreConfig('abtesting/accounts/active')){
33
+ $replace = Mage::getSingleton('core/design_package')->getPackageName()."/";
34
+ if(!$cookie){
35
+ $test = Mage::getStoreConfig('abtesting/current/test');
36
+ setcookie('abtesting',$test);
37
+ Mage::getSingleton('core/session')->setAbTesting('yes'); // temporarily set this to yes - so as not to double up this code
38
+ if($test == "a"){
39
+ $code = Mage::getStoreConfig('abtesting/accounts/acode');
40
+ Mage::getSingleton('core/session')->setAbTest('a');
41
+ if($code && !empty($code)){
42
+ $this->_theme[$type] = str_replace($replace,"",Mage::getStoreConfig('abtesting/accounts/adesign'));
43
+ }
44
+ Mage::getConfig()->saveConfig('abtesting/current/test','b');
45
+ } else {
46
+ $code = Mage::getStoreConfig('abtesting/accounts/bcode');
47
+ Mage::getSingleton('core/session')->setAbTest('b');
48
+ if($code && !empty($code)){
49
+ $this->_theme[$type] = str_replace($replace,"",Mage::getStoreConfig('abtesting/accounts/bdesign'));
50
+ }
51
+ Mage::getConfig()->saveConfig('abtesting/current/test','a');
52
+ }
53
+ } else {
54
+ $test = $cookie;
55
+ if($test == "a"){
56
+ $code = Mage::getStoreConfig('abtesting/accounts/acode');
57
+ if($code && !empty($code)){
58
+ $this->_theme[$type] = str_replace($replace,"",Mage::getStoreConfig('abtesting/accounts/adesign'));
59
+ }
60
+ } else {
61
+ $code = Mage::getStoreConfig('abtesting/accounts/bcode');
62
+ if($code && !empty($code)){
63
+ $this->_theme[$type] = str_replace($replace,"",Mage::getStoreConfig('abtesting/accounts/bdesign'));
64
+ }
65
+ }
66
+ }
67
+
68
+ }
69
+
70
+ /* end our cookie code */
71
+
72
+ return $this->_theme[$type];
73
+ }
74
+
75
+ }
app/code/local/Creare/Abtesting/Model/Source/Design.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Creare_Abtesting_Model_Source_Design
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return Mage::getSingleton('core/design_source_design')->getAllOptions();
8
+ }
9
+ }
app/code/local/Creare/Abtesting/etc/adminhtml.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <acl>
3
+ <resources>
4
+ <all>
5
+ <title>Allow Everything</title>
6
+ </all>
7
+ <admin>
8
+ <children>
9
+ <system>
10
+ <children>
11
+ <config>
12
+ <children>
13
+ <abtesting>
14
+ <title>CreareGroup - AB Testing</title>
15
+ </abtesting>
16
+ </children>
17
+ </config>
18
+ </children>
19
+ </system>
20
+ </children>
21
+ </admin>
22
+ </resources>
23
+ </acl>
24
+ </config>
app/code/local/Creare/Abtesting/etc/config.xml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Creare_Abtesting>
5
+ <version>0.1</version>
6
+ </Creare_Abtesting>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <abtesting>
11
+ <class>Creare_Abtesting_Block</class>
12
+ </abtesting>
13
+ </blocks>
14
+ <models>
15
+ <abtesting>
16
+ <class>Creare_Abtesting_Model</class>
17
+ <resourceModel>abtesting_mysql4</resourceModel>
18
+ </abtesting>
19
+ <core>
20
+ <rewrite>
21
+ <design_package>Creare_Abtesting_Model_Package</design_package>
22
+ </rewrite>
23
+ </core>
24
+ </models>
25
+ <helpers>
26
+ <abtesting>
27
+ <class>Creare_Abtesting_Helper</class>
28
+ </abtesting>
29
+ </helpers>
30
+ <events>
31
+ <controller_front_init_before>
32
+ <observers>
33
+ <clear_temp_session>
34
+ <type>singleton</type>
35
+ <class>abtesting/observer</class>
36
+ <method>removeAbSession</method>
37
+ </clear_temp_session>
38
+ </observers>
39
+ </controller_front_init_before>
40
+ <controller_action_layout_generate_blocks_after>
41
+ <observers>
42
+ <clear_temp_session_test>
43
+ <type>singleton</type>
44
+ <class>abtesting/observer</class>
45
+ <method>removeTempSession</method>
46
+ </clear_temp_session_test>
47
+ </observers>
48
+ </controller_action_layout_generate_blocks_after>
49
+ </events>
50
+ </global>
51
+ <frontend>
52
+ <layout>
53
+ <updates>
54
+ <abtesting>
55
+ <file>creare_abtesting.xml</file>
56
+ </abtesting>
57
+ </updates>
58
+ </layout>
59
+ </frontend>
60
+ <default>
61
+ <abtesting>
62
+ <accounts>
63
+ <active>0</active>
64
+ </accounts>
65
+ <current>
66
+ <test>a</test>
67
+ </current>
68
+ </abtesting>>
69
+ </default>
70
+ </config>
app/code/local/Creare/Abtesting/etc/system.xml ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <creare translate="label" module="abtesting">
4
+ <label>CreareGroup</label>
5
+ <sort_order>100</sort_order>
6
+ </creare>
7
+ </tabs>
8
+ <sections>
9
+ <abtesting translate="label" module="abtesting">
10
+ <label>AB Testing</label>
11
+ <tab>creare</tab>
12
+ <sort_order>1000</sort_order>
13
+ <show_in_default>1</show_in_default>
14
+ <show_in_website>1</show_in_website>
15
+ <show_in_store>1</show_in_store>
16
+ <groups>
17
+ <howto translate="label" module="abtesting">
18
+ <label>How to set it up</label>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>0</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <show_in_website>1</show_in_website>
23
+ <show_in_store>1</show_in_store>
24
+ <comment>
25
+ <![CDATA[
26
+ <p>First of all - make sure you have set your main Google Analytics account up. You'll find this under Google API in the left menu.</p>
27
+ <p>The main analytics accounts will run on every page - therefore you always have a full analytics account (not just showing A or B)</p>
28
+ <p>For a detailed write-up please see <a target="_blank" href="https://www.creare.co.uk/ab-split-testing-magento-with-google-analytics-cro">our supporting blog post</a>.</p>
29
+ ]]>
30
+ </comment>
31
+ </howto>
32
+ <accounts translate="label" module="abtesting">
33
+ <label>Manage your Google Analytics Accounts</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>10</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
+ <fields>
40
+ <active translate="label">
41
+ <label>Enabled</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>adminhtml/system_config_source_yesno</source_model>
44
+ <sort_order>10</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>1</show_in_store>
48
+ </active>
49
+ <acode translate="label">
50
+ <label>Analytics Code for Theme A</label>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>20</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
+ </acode>
57
+ <adesign translate="label">
58
+ <label>Theme A (Original Theme)</label>
59
+ <frontend_type>select</frontend_type>
60
+ <source_model>abtesting/source_design</source_model>
61
+ <sort_order>30</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
+ </adesign>
66
+ <bcode translate="label">
67
+ <label>Analytics Code for Theme B</label>
68
+ <frontend_type>text</frontend_type>
69
+ <sort_order>40</sort_order>
70
+ <show_in_default>1</show_in_default>
71
+ <show_in_website>1</show_in_website>
72
+ <show_in_store>1</show_in_store>
73
+ </bcode>
74
+ <bdesign translate="label">
75
+ <label>Theme B (New Theme)</label>
76
+ <frontend_type>select</frontend_type>
77
+ <source_model>abtesting/source_design</source_model>
78
+ <sort_order>50</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>1</show_in_store>
82
+ </bdesign>
83
+ </fields>
84
+ </accounts>
85
+ </groups>
86
+ </abtesting>
87
+ </sections>
88
+ </config>
app/design/frontend/base/default/layout/creare_abtesting.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="google_analytics">
5
+ <action method="setTemplate"><template>creare/abtesting/ga.phtml</template></action>
6
+ </reference>
7
+ </default>
8
+ </layout>
app/design/frontend/base/default/template/creare/abtesting/ga.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!Mage::helper('core/cookie')->isUserNotAllowSaveCookie()): ?>
2
+
3
+ <?php $accountId = Mage::getStoreConfig(Mage_GoogleAnalytics_Helper_Data::XML_PATH_ACCOUNT) ?>
4
+
5
+ <!-- BEGIN GOOGLE ANALYTICS CODEs -->
6
+ <script type="text/javascript">
7
+ //<![CDATA[
8
+ var _gaq = _gaq || [];
9
+ <?php echo $this->_getPageTrackingCode($accountId) ?>
10
+ <?php $code = $this->_getOrdersTrackingCode() // now we store it ?>
11
+ <?php echo $code; ?>
12
+
13
+ (function() {
14
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
15
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
16
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
17
+ })();
18
+
19
+ //]]>
20
+ </script>
21
+ <!-- END GOOGLE ANALYTICS CODE -->
22
+
23
+ <?php if(Mage::getStoreConfig('abtesting/accounts/active')): ?>
24
+
25
+ <?php $accountId = Mage::helper('abtesting')->getCode() ?>
26
+ <?php if($accountId && $accountId != ""): ?>
27
+ <!-- BEGIN GOOGLE ANALYTICS CODEs -->
28
+ <script type="text/javascript">
29
+ //<![CDATA[
30
+ var _gaq = _gaq || [];
31
+ <?php echo $this->_getPageTrackingCode($accountId) ?>
32
+ <?php echo $code; ?>
33
+
34
+ (function() {
35
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
36
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
37
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
38
+ })();
39
+
40
+ //]]>
41
+ </script>
42
+ <!-- END GOOGLE ANALYTICS CODE -->
43
+ <?php endif; ?>
44
+
45
+ <?php endif; ?>
46
+
47
+ <?php endif; ?>
app/etc/modules/Creare_Abtesting.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Creare_Abtesting>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </Creare_Abtesting>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Creare_Abtesting</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/OSL-3.0">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Split testing Magento using 3 seperate Google Analytics accounts - and 2 themes.</summary>
10
+ <description>If you've ever wanted to split-test Magento using themes (rather than individual pages) you can now do so.&#xD;
11
+ &#xD;
12
+ Simply set up a few extra analytics accounts, install our module and then analyse the differences between your visitors behaviour.&#xD;
13
+ &#xD;
14
+ The module will server 50% of your visitors your default theme, the other 50% will be served your new theme. &#xD;
15
+ &#xD;
16
+ One master analytics account then keeps track of all data, whereas 2 sub-accounts will only track the new theme vs. the old theme.</description>
17
+ <notes>First Release</notes>
18
+ <authors><author><name>Robert Kent</name><user>CreareGroup</user><email>magento@creare.co.uk</email></author></authors>
19
+ <date>2013-07-30</date>
20
+ <time>12:29:11</time>
21
+ <contents><target name="magelocal"><dir name="Creare"><dir name="Abtesting"><dir name="Helper"><file name="Data.php" hash="d9d134cccf8b6e4ea6c355ed21e64fd9"/></dir><dir name="Model"><file name="Observer.php" hash="37d434b7058b9020917104d320fc1306"/><file name="Package.php" hash="e4bdaac80c0a6dfcc5d1bddb058f22fb"/><dir name="Source"><file name="Design.php" hash="a3d5189ba9e68436656f4aca5496471d"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="e609a0349bd84701bce6890793449fd4"/><file name="config.xml" hash="e81fcb2110d6a442c23b6232437fb0dc"/><file name="system.xml" hash="5f85942cf016ec4a88199d83cf17f77e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Creare_Abtesting.xml" hash="072f6e9dd304888fc47fca724b8193b9"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="creare_abtesting.xml" hash="1d193e68f5f4f28431a06124cac6d377"/></dir><dir name="template"><dir name="creare"><dir name="abtesting"><file name="ga.phtml" hash="07544a8b83616d4a747ddb95af791f48"/></dir></dir></dir></dir></dir></dir></target></contents>
22
+ <compatible/>
23
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
24
+ </package>