Rich-text Reply

Get Section Name from Variation ID

Omid 01-26-17

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:

 

window['optimizely'].data.sections[variationId].name

 

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?

 

Level 2

Michal 01-27-17
 

Re: Get Section Name from Variation ID

Hi Omid,

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.

Thanks,
Optimizely
Omid 01-27-17
 

Re: Get Section Name from Variation ID

Yup, I'm looking at this article:
https://developers.optimizely.com/classic/javascript/reference/index.html

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.
Level 2
Michal 01-31-17
 

Re: Get Section Name from Variation ID

Hi Omid,

 

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:

 

window['optimizely'].data.sections[sectionId].name

 

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!

 

Best,

Optimizely
Omid 01-31-17
 

Re: Get Section Name from Variation ID

Objective is to pass along optimizely variations that are shown to our in-house analytics via ajax call.

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.
Level 2
Michal 02-01-17
 

Re: Get Section Name from Variation ID

Thanks for the insight Omid, much appreciated. Unfortunately, I'm not aware of a way to get the section IDs without another iteration. So good to know that the experiment-variation key-value pairs are sufficient for you Smiley Happy
Optimizely