-
Notifications
You must be signed in to change notification settings - Fork 0
/
ab-testing.js
1 lines (1 loc) · 7.76 KB
/
ab-testing.js
1
(()=>{"use strict";var t={853:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=r(338),i=r(83),o=r(675),a=function(){function t(t){this.initConfig=t}return t.prototype.init=function(){var t=this.pickVariant();this.setVariant(t,new n.Base64Decoder)},t.prototype.setVariant=function(t,e){this.removeBundledLinkTags(),document.open(),document.write(e?e.decode(t.html):t.html),document.close()},t.prototype.removeBundledLinkTags=function(){Array.from(document.querySelectorAll("link")).forEach((function(t){t.remove()}))},t.prototype.pickVariant=function(){var t=new i.VariantRequest(this.initConfig),e=new o.CriteriaAlwaysRandom;return e.setNext(new o.CriteriaQueryString).setNext(new o.CriteriaWinner).setNext(new o.CriteriaCookie).setNext(new o.CriteriaRandom).setNext(new o.CriteriaController).setNext(new o.CriteriaFirstVariant).setNext(new o.CriteriaNotFound),e.run(t)},t}();e.default=a},528:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.QUERY_PARAM_ALWAYS_RUN=e.COOKIE_EXP_DAYS=e.COOKIE_NAME=e.COOKIE_PREFIX=void 0,e.COOKIE_PREFIX="landerlab-ab-test",e.COOKIE_NAME="Landerlab_ABTesting",e.COOKIE_EXP_DAYS=7,e.QUERY_PARAM_ALWAYS_RUN="alwaysRun"},502:function(t,e,r){var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a};Object.defineProperty(e,"__esModule",{value:!0}),e.CookieService=void 0;var i=r(528),o=function(){function t(){}return t.prototype.setCookie=function(t,e,r){var n="";if(r){var i=new Date;i.setTime(i.getTime()+24*r*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=t+"="+(e||"")+n+"; path=/"},t.prototype.getCookie=function(t){for(var e=t+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var i=r[n];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(e))return i.substring(e.length,i.length)}return null},t.prototype.getIDFromCookieValue=function(t){if(!t)return null;var e=n(t.split(":"),2),r=e[0],o=e[1];if(r!==i.COOKIE_PREFIX)return null;var a=Number(o);return isNaN(a)?null:a},t.prototype.deleteAllCookies=function(){for(var t=document.cookie.split(";"),e=0;e<t.length;e++){var r=t[e],n=r.indexOf("="),i=n>-1?r.substr(0,n):r;document.cookie=i+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT"}},t}();e.CookieService=o},675:function(t,e,r){var n,i=this&&this.__extends||(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)});Object.defineProperty(e,"__esModule",{value:!0}),e.CriteriaNotFound=e.CriteriaAlwaysRandom=e.CriteriaFirstVariant=e.CriteriaController=e.CriteriaRandom=e.CriteriaCookie=e.CriteriaQueryString=e.CriteriaWinner=void 0;var o=r(528),a=r(111),u=r(502),l=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){return e.variantWithMaximumWeight?e.variantWithMaximumWeight:t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaWinner=l;var s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){return e.variantThatMatchesQueryString?e.variantThatMatchesQueryString:t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaQueryString=s;var c=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){return e.variantThatMatchesCookie?e.variantThatMatchesCookie:t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaCookie=c;var p=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){var r,n=[];for(r=0;r<e.allVariants.length;r++)n[r]=e.allVariants[r].weight+(n[r-1]||0);var i=Math.random()*n[n.length-1];for(r=0;r<n.length&&!(n[r]>i);r++);var a=e.allVariants[r];return a?((new u.CookieService).setCookie(o.COOKIE_NAME,o.COOKIE_PREFIX+":"+a.id,o.COOKIE_EXP_DAYS),a):t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaRandom=p;var f=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){return e.variantController?e.variantController:t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaController=f;var d=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){return e.firstVariant?e.firstVariant:t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaFirstVariant=d;var h=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(e){return e.hasAlwaysRunRandom?(new p).run(e):t.prototype.run.call(this,e)},e}(a.RuleHandler);e.CriteriaAlwaysRandom=h;var y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return i(e,t),e.prototype.run=function(t){throw new Error("No variant was found for request: "+t)},e}(a.RuleHandler);e.CriteriaNotFound=y},338:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Base64Decoder=void 0;var r=function(){function t(){}return t.prototype.decode=function(t){return decodeURIComponent(escape(atob(t)))},t}();e.Base64Decoder=r},607:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(r(853));window.LanderlabABTesting=new i.default(window.variants),window.LanderlabABTesting.init()},83:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.VariantRequest=void 0;var n=r(502),i=r(528),o=function(){function t(t){this.variants=t,this.queryStringParams=new URLSearchParams(window.location.search);var e=new n.CookieService,r=e.getCookie(i.COOKIE_NAME);this.cookieInformationID=e.getIDFromCookieValue(r)}return Object.defineProperty(t.prototype,"allVariants",{get:function(){return this.variants.experiments},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"variantWithMaximumWeight",{get:function(){return this.variants.experiments.find((function(t){return 100===t.weight}))||null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"variantThatMatchesQueryString",{get:function(){var t=Number(this.queryStringParams.get("variant"));return Number.isFinite(t)&&this.variants.experiments.find((function(e){return e.id===t}))||null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"variantThatMatchesCookie",{get:function(){var t=this;return Number.isFinite(this.cookieInformationID)&&this.variants.experiments.find((function(e){return e.id===t.cookieInformationID}))||null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"variantController",{get:function(){return this.variants.experiments.find((function(t){return!0===t.controller}))||null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"firstVariant",{get:function(){return 0===this.variants.experiments.length?null:this.variants.experiments[0]},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasAlwaysRunRandom",{get:function(){return"true"===this.queryStringParams.get(i.QUERY_PARAM_ALWAYS_RUN)},enumerable:!1,configurable:!0}),t}();e.VariantRequest=o},111:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.RuleHandler=void 0;var r=function(){function t(){}return t.prototype.setNext=function(t){return this._next=t,t},t.prototype.run=function(t){return this._next.run(t)},t}();e.RuleHandler=r}},e={};!function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(607)})();