I'm trying to use Google Content Experiments API to run several A/B tests simultaneously in the same page (similar to a multivariate test). I've tried just putting all the recommended code for each test one after another, like this:
<script src="//www.google-analytics.com/cx/api.js?experiment=8RsNt4b7T0aE8RC2s9R3IA">/script>
<script>
var chosenVariation = cxApi.chooseVariation();
var pageVariations = [
function() {},
function() {
$(".block1").hide();
},
];
$(document).ready(
pageVariations[chosenVariation]
);
</script>
<script src="//www.google-analytics.com/cx/api.js?experiment=T3m-MvunQ6wY6StbPDqzTg"></script>
<script>
var chosenVariation = cxApi.chooseVariation();
var pageVariations = [
function() {},
function() {
$(".block2").hide();
}
];
$(document).ready(
pageVariations[chosenVariation]
);
</script>
This is working but not correctly: All the tests get visitors according to the Google Analytics dashboard, but the last one to appear in the code gets a lot of them (probably all the real visitors to the page) and the others only a fraction of the total visitors. I guess this could be related to loading the "cx/api.js" script several times.
After searching a lot, I've found two related issues with possible solutions, but I don't fully understand how they work:
https://productforums.google.com/forum/#!topic/analytics/R3u8yagLr48
How can you choose variations for several content experiments? (I've tried to comment on this answer instead of creating a new question, but I don't have enough reputation in StackOverflow to comment).
I guess the solution could be some variation of the code provided in the answer of the last link, but I don't know much Javascript and therefore don't know what I should change exactly to achieve what I want (multiple experiments concurrently in the same page).
Thanks a lot for your help! ;)
来源:https://stackoverflow.com/questions/23524229/run-multiple-simultaneous-tests-with-google-content-experiments-api