当我在我的网站上运行实验时,我希望能够找出当前访问者看到的测试和变体。我无法从Optimizely Javascript API找到如何做到这一点。
问问题
3625 次
2 回答
20
您可以获取第一个正在运行的实验的 ID(假设您有一个),然后是变体索引(例如,0、1、2)、名称和 ID:
var experimentID = window['optimizely'].data.state.activeExperiments[0];
var variationIndex = window['optimizely'].data.state.variationMap[experimentID];
var variationName = window['optimizely'].data.state.variationNamesMap[experimentID];
var variationID = window['optimizely'].data.state.variationIdsMap[experimentID];
于 2013-09-24T14:00:55.417 回答
6
扩展 Kevin Borders 的答案。您可能在一个页面上运行了多个实验。我在下面包含了一个代码片段,演示了如何返回一组活动的变体 ID:
// Return a list of active Optimizely variation IDs
function activeVariations(){
// Multiple variations may currently be active
var activeVariations = [];
// Get state settings from optimizely object
var state = window['optimizely'].data.state;
// For each of the active experiments:
for (var i = state.activeExperiments.length - 1; i >= 0; i--) {
// Current experiment ID
var experimentID = state.activeExperiments[i];
// Current corresponding variation ID
var variationID = state.variationIdsMap[experimentID];
// If we have an active variation, add it to our array
if (variationID) { activeVariations.push(variationID[0]); }
}
// List of active variations
return activeVariations;
}
于 2015-07-30T18:30:37.887 回答