Rich-text Reply

Pulling variant out of cookie

jonsinclair1 02-05-16
Accepted Solution

Pulling variant out of cookie

Is there a way to identify which variant a user is in from the cookie, and pass that data through to our server? We want to use this to hand off the user from the optimizely test to our own split-generator. 

Joel_Balmer 02-05-16
 

Re: Pulling variant out of cookie

Hi @jonsinclair1,

 

Definitely the easiest way of extracting this value is using Optimizely's data object, here (full reference, here). Once you extract the variationID(s) you need, you will need to setup pushing them onto your server.

 

If you really do need to read from the cookie directly, you will need to write code to perform the following:

 

  1. Get the cookie (example here)
  2. Pass the above function the optimizelyBuckets cookie name (see all our cookies, here)
  3. Parse the JSON returned, here, and decodeURIComponent, here - this answer here is pretty great.

 

Now, you have an object with 'experimentID:variationID' as name:value pairs. The object contains items (name:value pairs) for all the experiments the user has ever been bucketed into for that page (Note: The JS API for this, here, only returns experiments running for the visitor and inactive experiments for which the user has been bucketed).

 

I hope those resources help you write the custom code needed (or of course, use the simple Optimizely JS API) Smiley Happy

 

Cheers!