Get Section Name from Variation ID
Looking at the Optimizely Classic developer reference it shows that you can get a Section Name using Variation ID using:
However this results in an undefined error.
I've noticed that this actually only works by using the sectionId instead of variationId. Is there any way I can get a section name if I only have the Variation ID?
Thanks for posting here! I'm not quite sure what exactly you mean by the Section (Names)? Can you please also point me to the article you're referring to? That will help me to put your question in more context.
Under "Sections" there is a reference for Section Name that says to pass in the Variation ID, but it really needs the Section ID in order to get the Section Name, but I'd like to be able to get a Section Name, or even a Section ID for that matter, by using the Variation ID.
I see now! I had a look at the article and did some testing and I believe there is a 'typo' in the article - as you correctly point out, in order to get a section name you have to use the following API call:
The above API call follows the logic of other comparable calls where you're providing an ID of the entity that you're calling beforehand -> ...experiments[experimentID]..., ...variations[variationID]..., sections[sectionID]...
To get a Section ID knowing only the Variation ID is technically possible - you can iterate over all the variations until you find your Section ID, although this isn't optimal. Would you mind sharing what's the use case here? Also, note that if moving to Optimizely X is an option for you, there are no sections there anymore.
In any case, thanks a lot for your input - we will update our Dev Docs promptly to avoid further confusion!
I'm currently using window.optimizely.data.state.variationIdsMap in order to get key-value pairs of active experiments (as the key) to active variations (as the value). The only missing piece is that I'd like to be able to send our data team the section id that each variation belongs to as well, without having to put in additional iteration in order to get the section. The experiment-variation key-value pair is sufficient and the section name is more of a nice-to-have, but I just thought I'd ask to see if it was something that could be done easily.