javascriptgoogle-analyticsgoogle-experiments

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: https://developers.google.com/analytics/solutions/experiments-server-side)

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

<script>
cxApi.setChosenVariation(1, 'a9BcDEFgHijKl8mON-Opqw');
</script>

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:

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

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


Solution

  • 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');
    });