Rich-text Reply

Is it possible to know the current experiment ID from within Global Javascript?

lkraav 12-24-14

Is it possible to know the current experiment ID from within Global Javascript?

[ Edited ]
I'd like to avoid having to manually specify an experiment ID variable in Global JS for various integration purposes. If it'd be possible to get the experiment ID that runs this particular Global JS snippet, programmatically, integration code would become fully copy-paste with no manual modification needed. window['optimizely'].data.state.activeExperiments doesn't look like something that helps because the order of experiments there is static.
--
Leho, marketing & tech architect | G+: lkooglizmus@gmail.com
Level 4

JDahlinANF 12-25-14
 

Re: Is it possible to know the current experiment ID from within Global Javascript?

Confused on what you are actually looking for

 

Do you want to know all of the experiment/variation combinations that are affecting the current page?

Do you want to know all of the active experiment/variation combinsations that the user is part of (anywhere on the site)?

or

Do you have an experiment that is adding a script reference to a file and you want to be able to know which experiment./variation is making the script reference?

lkraav 12-25-14
 

Re: Is it possible to know the current experiment ID from within Global Javascript?

[ Edited ]

> Do you want to know all of the experiment/variation combinations that are affecting the current page?

No. I can get that with window['optimizely'].data.state.activeExperiments.

> Do you want to know all of the active experiment/variation combinsations that the user is part of (anywhere on the site)?

No. I can probably get that with another optimizely object member variable.

>Do you have an experiment that is adding a script reference to a file and you want to be able to know which experiment./variation is making the script reference?

Yes exactly. When there are x+1 concurrent running on a page, and each of them has something in "Global Javascript", that JS would need to know which experiment is executing it.

 

PS how do I get my signature off the posts? Spent like 10 minutes in the Profile control panel, no checkmarks for signatures that I could see!

--
Leho, marketing & tech architect | G+: lkooglizmus@gmail.com
Level 4
JDahlinANF 12-26-14
 

Re: Is it possible to know the current experiment ID from within Global Javascript?

[ Edited ]

There is not anything that I have found that lets me get the value of NNNNNNN that runs the code found in optimizely.data.variations[NNNNNNNN].code.  I'll be keeping an eye on this thread to see if anyone has a solution for it

 

It would be nice to be able to do something like this in the code editor:

var script_a= window.document.createElement("script");
script_a.src='http://www.example.com/path_to_JS_goes_here.js?optimizelyVariation=' + _optly.variation;
window.document.head.insertBefore(script_a, document.head.childNodes[0]);

 

As for your signature - "My Profile" --> "edit" --> "Personal Information"

JDahlinANF 12-26-14
 

Re: Is it possible to know the current experiment ID from within Global Javascript?

Since you know the experiment id, try using variationIdsMap - since a user can only be in one variation of each experiment, this should contain only the id of that specific variation/

 

It works in my console - and, since it is evaluated at run time, after the optimizely object is defined, I presume it it works in a code block in the editor, but I have not tried it out.  You'll need to replace NNNNNNN with your experiment's id.

[code]

optimizely.variationIdsMap[NNNNNNN].toString()

[/code]

 

agenta 12-30-14
 

Re: Is it possible to know the current experiment ID from within Global Javascript?

I wrote a method to activate experiments based on matching the url to the argument that's passed in.

[code]
activateExperiment : function(step) {
window.optimizely = window.optimizely || [];
if(_.keys(window.optimizely).length > 0){
if(_.keys(window.optimizely.allExperiments).length > 0){
_.each(window.optimizely.allExperiments, function(v, i){
if(v.activation_mode == "manual" && v.enabled && v.urls[0].value.match(step)) {
window.optimizely.push(["activate", i]);
}
});
}
}
}
[/code]
Level 2