bencoder bencoder - 4 months ago 48x
Javascript Question

Multiple experiments with google analytics api

We use the analytics api to download the experiments and variations, and do the variation selection for our visitors on our end (i.e. Server-side experiments as described here:

When a visitor visits a url that is under experimentation and they have a selected variation, they get the javascript as described like:

cxApi.setChosenVariation(1, 'a9BcDEFgHijKl8mON-Opqw');

This is working fine. We would like to have multiple experiments running(For example, a site-wide experiment involving the menu, and a page-specific experiment), the variation selection and everything works fine on our end. To the user, when they are part of multiple experiments, they get multiple calls of setChosenVariation like so:

cxApi.setChosenVariation(1, 'a1BcDEFgHijKl2mON-3pqr');
cxApi.setChosenVariation(1, 'z9YxWVVuTsrPl8oNM-7lkj');

I can't find any reason why this shouldn't work, but in the results from the experiments, when this happens, we see all the users being assigned only to one experiment, though both experiments have results (creating conversion rates of >100%).

conversion rate > 100%

Is there an explanation of this behaviour (I feel like perhaps the second call is overriding the first call?) and/or a correct way to do this?

Thanks very much


Ease answer didn't work for me. Thanks to Google Analytics Debugger extension I could see that both those ga('send','pageview') were sending data about second experiment. Using synchronous call worked and I ended up with something like:

var sendExperiment = function(tracker, experimentVar, experimentId) {
  cxApi.setChosenVariation(experimentVar, experimentId);
  tracker.send('event', 'experiment', 'view',{'nonInteraction': 1});

ga(function(tracker) {
 sendExperiment(tracker, 1, 'a1BcDEFgHijKl2mON-3pqr');
 sendExperiment(tracker, 2, 'z9YxWVVuTsrPl8oNM-7lkj');