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.
Solved! Go to Solution.
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:
- Get the cookie (example here)
- Pass the above function the optimizelyBuckets cookie name (see all our cookies, here)
- 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)