1

I have the following script:

<script src="//www.google-analytics.com/cx/api.js?experiment=XXXXXXXXXXXXXXXXXXXXXXX"></script>
<script>

  // Determine the current chosen variation
  console.log( cxApi.getChosenVariation() ); // returns -1 (equivalent to cxApi.NO_CHOSEN_VARIATION)

  // Tell Google to choose a variation for me
  var variation = cxApi.chooseVariation();
  console.log( variation );  // returns 0  <-- original variation

  // Determine current chosen variation again
  console.log( cxApi.getChosenVariation() ); // returns -1 again... why?

  // Lets force a chosen variation:
  variation = cxApi.setChosenVariation(1);

  // And determine the chosen variation one more time:
  console.log( variation ); // returns 1, as expected

</script>

So what is going on here? It seems like using chooseVariation() is not working. Google is not choosing a variation for me. It's returning zero but then it says a variation hasn't been chosen. It's only when I choose a variation myself that everything seems to work.

Jake Wilson
  • 88,616
  • 93
  • 252
  • 370

0 Answers0