Skip to content

Instantly share code, notes, and snippets.

@vchub
Created October 11, 2013 10:08
Show Gist options
  • Select an option

  • Save vchub/6932435 to your computer and use it in GitHub Desktop.

Select an option

Save vchub/6932435 to your computer and use it in GitHub Desktop.

Revisions

  1. vchub revised this gist Oct 11, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion split_cookie.js
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@

    return splitVal;
    }
    // </script>
    </script>
    // ....
    // </head>

  2. vchub created this gist Oct 11, 2013.
    44 changes: 44 additions & 0 deletions split_cookie.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    // head>
    // ...
    <script type="text/javascript">
    /* A/B splitting - Returns either "A" or "B". */
    function getABsplit() {
    var cookieDomain = ".your_domain.ru";
    var cookieName = "gr_split_GLOBAL";
    var cookieExpire = +new Date()+1000*60 * 60 * 24 * 365;

    // get cookie
    var m = (new RegExp(cookieName+"=([^;]*)")).exec(document.cookie);
    var splitVal = (m == null ? null : unescape(m[1]));

    if (splitVal == "A" || splitVal == "B") {return splitVal}
    splitVal = (Math.random() < 0.5) ? "A" : "B";

    // set cookie
    document.cookie =
    cookieName + "=" + escape(splitVal) +
    ";expires=" + new Date(cookieExpire).toUTCString()+
    ";path=/" +
    ((cookieDomain != null) ? ";domain=" + cookieDomain : "");

    return splitVal;
    }
    // </script>
    // ....
    // </head>


    // using gravity set cookie
    if ($.cookie('gr_split_GLOBAL') != "A") {

    _gravity.push({
    type: 'recommendation',
    callback: callback_fn,
    numberLimit: 5,
    scenarioId: "ITEM_PAGE",
    currentRegionId: 0,
    currentItemId: 287265,
    resultNames: ["itemId"]
    });
    };