Get visitor's Optimizely A/B test and variation

后端 未结 2 899
北海茫月
北海茫月 2021-02-04 08:02

When I run an experiment on my website, I want to be able to find out which test and variation the current visitor sees. I can\'t find how to do this from the Optimizely Javascr

2条回答
  •  心在旅途
    2021-02-04 08:50

    You can get the ID of the first running experiment (assuming you have one), and then the variation index (e.g., 0, 1, 2), name, and 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];
    

提交回复
热议问题