I'm trying to create ab testing experiment using Google Content Experiments JavaScript API (according to https://developers.google.com/analytics/devguides/collection/analyticsjs/experiments). I thought user should always see only one experiment, but chooseVariation gives me different values (0 or 1) if I refresh page. It seems it always just randomly choose 0/1 and doesn't remember chosen value.

What could cause this problem/behaviour? (experiment is running)

Here is my code (on localhost):

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

        <script>
            var g_exp_id = "HTuY9pj1SPCOkYUkMz1Tvg";
            var chosenVariation = cxApi.chooseVariation();
            console.log(chosenVariation); //always gives different values (0 or 1) for the same user (after refreshing the page)
        </script>

    </body>
</html>
1

There are 1 best solutions below

0
On

Could it be that you're not letting GA to write the cookie values? That should help GA to remember the experiment variation, picked for user.