Optimize
5.2K members online now
5.2K members online now
Learn how to create your first experiment and get tips on creating A/B, redirect, and multivariate tests.
Guide Me
star_border
Reply

Identifying the test variation within javascript

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Is there a way to get the test variation through Javascript? I posted this question earlier, but it seems like it might've been deleted. Not sure what's up with that.

 

I'd have a variation that I would like to test, but it's not feasible to do through the wysiwyg editor. So I'm thinking I would like to do something like this below:

 

 

if (something.getUserTestVariation() === 1) {
   render(...); // render the new variation
} else {
   render(...); // render the default variation
}

Is this possible to do with the APIs? I've tried looking at ga.getAll()[0].plugins_, but I don't see any fields that would hint to getting an identifier for the variation.

 

Thanks!

 

PS:

I noticed somebody else had a similar question posted on StackOverflow: https://stackoverflow.com/questions/44412241/is-it-possible-to-read-experimentid-and-variationid-in-...

 

Unfortunately, the solution provided (setting a window variable) isn't possible for me and causes a race condition between the code executed by Google Optimize and my own code.