I need to add the google experiment code `
<!-- Google Analytics Content Experiment code -->
<script>function utmx_section(){}function utmx(){}(function(){var
k='82207727-1',d=document,l=d.location,c=d.cookie;
if(l.search.indexOf('utm_expid='+k)>0)return;
function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.
indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.
length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write(
'<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':
'://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+
'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().
valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"><\/sc'+'ript>')})();
</script><script>utmx('url','A/B');</script>
<!-- End of Google Analytics Content Experiment code -->
`directly after the head-tag of a specific product. So I put this code without any addition into a gec.js file and put the file in the root/js folder. In the custom layout update field of the specific product I try to call the script using
<reference name="head">
<action method="addJs">
<script>gec.js</script>
</action>
</reference>
I don't get any errors after loading the productpage on the frontend. But Google experiment code verification fails. How do I get this to work?
So it took me days to figur this out.
This is the solution. First create a static block with the name "google_experimental_code". This should contain your Google Experiment code AND your Google Analytics tracking cookie. Pay attention here. EXACTLY copy the code and past it in the static blockt with the WYSIWYG turned off. Without turning the editor one save block. Do not beautify the code of Google because google will fail to recognise the code. The GA code needs to be put in this block aswell to solve the problem during the verification proces where the GA code is before the experiment code. (read on for more)
In local.xml add after
means that the code is only executed on the product with ID=1 is needed to remove the static block that contains the google analytics code on the product page. Since I put it in the experiment block it can be removed here.
Create a static block with the name
google_analytics_code
containing your GA tracking code.In Magento Backend disable the Google API part Google Analytics.
Tips: Create a static block containing a Hello world script. Work with this script untill you need the GEC code. Check if your productpage is the same in all views and does not contain a language dependant alteration. I did not find a way to add this using widgets since the reference Head is missing. My script which checks how much of a page is read is now broken. Probably due to a different sequence of the GA script.