cxApi.chooseVariation() always returning 0

不问归期 提交于 2020-01-02 07:57:08

问题


My site is a single page webapp. I'm loading the experiment code with my experiment id:

<script src="//www.google-analytics.com/cx/api.js?experiment={@ js_settings.analytics.experimentid @}"></script>

After all is loaded, at the moment I display the page, I select the right template by calling a function which does the following:

ga('set', 'expId', experiment_id);
var variation = cxApi.getChosenVariation(experiment_id) || cxApi.chooseVariation();
cxApi.setChosenVariation(variation, experiment_id);
ga('set', 'expVar', variation);
ga('set', 'dimension1', variation);
ga('send', 'pageview');

Now, it seems like cxApi.chooseVariation() always returns 0. 100% of the 205 sessions so far were given the default variation (0). Why?


回答1:


The problem seems to have been that the experiment javascript code is required to be present on the page even if you manually use cxApi. You have to modify the code such that it doesn't redirect the user and then you can call chooseVariation() and it will return an actual variation, instead of always 0.

Surely this API should be improved because in its current state it's mediocre at best.



来源:https://stackoverflow.com/questions/37883236/cxapi-choosevariation-always-returning-0

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