Split test A/B PHP Script
Magento is quite limited in tools like conversion optimalisation like A/B testing or multivariate testing. That is why I created a very simple php script that you can put directly into a phtml file. It’s a bit hacky, that it’s not via the core, but it works though and is fast. This script has its limitation, see the note on the bottom.
If you want to variate the text of a button on the product page and go to a file like /app/design/frontend/default/default/catalog/product/view.phtml and insert this into the header (in the php-code):
srand((double)microtime()*1000000); $var = array(); $var[1]['name'] = 'direct'; $var[1]['value'] = 'Buy direct'; $var[2]['name'] = 'purchase'; $var[2]['value'] = 'Purchase product'; $var[3]['name'] = 'invest'; $var[3]['value'] = 'Invest in product'; $choice = cookieCheck($var); function cookieCheck($var) { $cookie = Mage::getSingleton('core/cookie'); $cookievalue = $cookie->get('variation_test'); if (isset($cookievalue) && ($cookievalue > 0)) { $choice = $cookievalue; } else { $choice = rand(1,count($var)); $cookie->set('variation_test', $choice ,time()+30*86400,'/'); } return $choice; }
Then create a piece of text like a link or a button. That is where the variation takes place:
<? echo $var[$choice]['value']; ?>
If you want to track the variable in Google Analytics, you can edit the template file /app/design/frontend/default/default/googleanalytics/ga.phtml , so it gets like:
srand((double)microtime()*1000000); $var = array(); $var[1]['name'] = 'direct'; $var[1]['value'] = 'Buy direct'; $var[2]['name'] = 'purchase'; $var[2]['value'] = 'Purchase product'; $var[3]['name'] = 'invest'; $var[3]['value'] = 'Invest in product'; $choice = cookieCheck(); function cookieCheck() { $cookie = Mage::getSingleton('core/cookie'); $cookievalue = $cookie->get('variation_test'); if (isset($cookievalue) && ($cookievalue > 0)) { $choice = $cookievalue; } else { $choice = rand(1,count($var)); $cookie->set('variation_test', $choice ,time()+30*86400,'/'); } return $choice; } ?> isUserNotAllowSaveCookie()): ?>
Note: This script could not work properly if you’re using Full Page Cache. Also it could not work with the page block html cache. So, work in progress …
Hello, I’ve tested the script. While it seems to work ok, I still get discrepancies between the test results in Google Analytics.
Moreover, now I need to test different titles and layout of product pages. I found this extension https://amasty.com/magento-ab-testing.html
Have you heard anything about it?