Run multiple simultaneous tests with Google Content Experiments API

二次信任 提交于 2019-12-06 04:37:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!