简体   繁体   中英

cxApi.chooseVariation() always returning 0

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM