cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing Google Analytics A/B testing script

Implementing Google Analytics A/B testing script

Hi there,

 

my team is wondering what is the best way to add a script like the google analytics A/B testing script to a magento site (just one page over the Design --> Layout Update XML field in the backend of CMS pages and categories.

 

The script is something like:

 

<!-- Google Analytics Content Experiment code -->
<script>function utmx_section(){}function utmx(){}(function(){var
k='1.......

><\/sc'+'ript>')})();
</script><script>utmx('url','A/B');</script>
<!-- End of Google Analytics Content Experiment code -->

 

The google instruction is to ad this code just after the opening "head" tag of the page so it must be something like:

 

<referenceContainer name="head">
...
</referenceContainer>

 

But how can we ad the script here directly or is there another better way to ad this just for one page.

 

Many thanks!

1 REPLY

Re: Implementing Google Analytics A/B testing script

I don't think you would be able to do the intended task with the approach you mentioned. Why don't you take an external help and use this extension. I've used it in the past to compare results for my site:

 

Integrating Magento plugin with VWO is very simple and does not require you to fiddle with your template source code. We recommend that you first install Magento and then integrate the VWO module. Integrating the VWO code before installing Magento may give you errors during the integration.

Follow these steps to integrate VWO with Magento:

    1. Download the plugin and extract the files on your local system.
    2. Copy and paste the folder “app” into your website root directory. Click  “Yes” to overwrite files, if prompted.
    3. Logout and login to Magento.
    4. In Admin Panel of your site, go to Configurations under System menu.
    5. In left panel, under section titled Wingify, click A/B testing using Visual Web Optimizer.
    6. On the configurations page of the plugin, activate the plugin and enter your VWO account ID.
    7. Create and run your VWO campaigns.

Note: You will still need to add additional code for revenue goal and the custom conversion goal.



The following snippet of code also needs to be loaded before the end of head tag on the live site.

 
<!-- Start Visual Website Optimizer Asynchronous Code -->
<script type='text/javascript'>
var _vwo_code=(function(){
var account_id=172373,
settings_tolerance=2000,
library_tolerance=2500,
use_existing_jquery=false,
// DO NOT EDIT BELOW THIS LINE
f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById('_vis_opt_path_hides');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement('script');b.src=a;b.type='text/javascript';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName('head')[0].appendChild(b);},init:function(){settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&r='+Math.random());var a=d.createElement('style'),b='body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}',h=d.getElementsByTagName('head')[0];a.setAttribute('id','_vis_opt_path_hides');a.setAttribute('type','text/css');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init();
</script>
<!-- End Visual Website Optimizer Asynchronous Code -->