- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Getting section and variation id via Javascript to use in experiment

Getting section and variation id via Javascript to use in experiment
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Within an experiment with two sections i have to identify which variation from the other segment is active. To give an example:
Section A has two variations a1 and a2. Section B has two variations as well, b1 and b2. In b2 i have to create a link, which depends on the variation of A being active. If a1 is active, the link in b1 hast to be set to e.g. "www.google.de", if a2 is active it must be set to "www.facebook.de".
Any advice is welcome, Thank you very much in advance
Kind regards
Michael
Michael




Solved! Go to Solution.

Re: Getting section and variation id via Javascript to use in experiment
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hey Michael!
This gets pretty advanced pretty quickly. You'll want to set a flag in the force loop and then pivot off of it in Section B. Example code + docs below:
a1.js
/* _optimizely_evaluate=force */ window.sectionblink = 'http://google.de'; /* _optimizely_evaluate=safe */
a2.js
/* _optimizely_evaluate=force */ window.sectionblink = 'http://facebook.de'; /* _optimizely_evaluate=safe */
b1.js
$('#link-foo').attr('href', window.sectionblink);
Force Code Docs: http://bit.ly/1f6WgbR
Hope that helps!
- Tom Fuertes | CTO @ CROmetrics / LinkedIn
"Most Impactful Use of Personalization" and "Experience of the Year" Optie award winner.

Re: Getting section and variation id via Javascript to use in experiment
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi @CouchPsycho,
I really like @tomfuertes' approach and it works great.
Here's another option if you want to contain this evaluation to just the variation code in section B, and get some practice parsing our data object. By the time the evaluate_force tag runs, the visitor has been bucketed and the Optimizely data object knows which variations they're seeing. Thus, you can parse the data object and set the link href based on which section thy're seeing for section A. The key is knowing which part of the data object to use and what its format is.
We'll use optimizely.variationNamesMap which shows, for every experiment the visitor is eligible to see, which variation they're bucketed into. In an MVT, this returns a string list of each variation name, in sequential order of how your sections are defined in your experiment editor. For example, if I plug this into the browser console:
optimizely.variationNamesMap[1369953963]
my response will be:
"Black, Original"
where Black is the name of the variation in section 1, and Original is the name of the variation in section 2. Note that you'll get the variation names only if you haven't masked descriptive names in your project's Privacy Settings; otherwise, your response will look like:
"Var 1358903957, Var 1368957077"
Given this response list, it's pretty straightforward to check the value for section 1 and set the href accordingly:
//use this if your descriptive names are NOT masked
/* _optimizely_evaluate=force */ if (optimizely.variationNamesMap[1369953963].split(", ")[0] == "Black") { $('#link-foo').attr('href', 'www.google.de'); } else { $('#link-foo').attr('href', 'www.facebook.de'); } /* _optimizely_evaluate=safe */ //...OR... //use this if your descriptive names ARE masked
/* _optimizely_evaluate=force */ if (optimizely.variationNamesMap[1369953963].split(", ")[0].split(" ")[1] == "1358903957") { $('#link-foo').attr('href', 'www.google.de'); } else { $('#link-foo').attr('href', 'www.facebook.de'); } /* _optimizely_evaluate=safe */
We'd love to hear which approach you decide to take!
Solutions Architect | Optimizely, Inc.
harrison@optimizely.com


Re: Getting section and variation id via Javascript to use in experiment
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Michael



