Comparing version 0.0.22 to 0.0.23
@@ -299,3 +299,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.autotune = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
html_1.startHTMLExperiments(); | ||
return [2, {}]; | ||
return [2]; | ||
} | ||
@@ -302,0 +302,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).autotune=e()}}(function(){return function i(s,u,a){function p(t,e){if(!u[t]){if(!s[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=u[t]={exports:{}};s[t][0].call(o.exports,function(e){return p(s[t][1][e]||e)},o,o.exports,i,s,u,a)}return u[t].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)p(a[e]);return p}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var s=e(".");function p(e){for(var t=0,n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t&=t}return t}function c(e){return e.getAttribute("option")||p(e.outerHTML).toString()}n.startHTMLExperiments=function(){var i=function(){for(var e={},t=document.querySelectorAll("[data-experiment]"),n=0;n<t.length;n++){var r=t.item(n),o=r.getAttribute("data-experiment"),i=r.getAttribute("data-option"),s=e[o];void 0===s&&(s=e[o]={options:[],nodes:[]}),-1===s.options.indexOf(i)&&s.options.push(i),s.nodes.push(r)}return e}(),n=function(){for(var e={},t=document.getElementsByTagName("autotune"),n=0;n<t.length;n++){for(var r=t.item(n),o=r.getAttribute("experiment")||p(r.innerHTML).toString(),i={node:r,options:[]},s=0;s<r.children.length;s++){var u=r.children.item(s);i.options.push(c(u))}var a=e[o]||[];a.push(i),e[o]=a}return e}();Object.getOwnPropertyNames(i).forEach(function(e){var t=i[e],n=t.options,r=t.nodes,o=s.oneOf(e,n);r.forEach(function(e){e.getAttribute("data-option")!==o&&e.remove()})}),Object.getOwnPropertyNames(n).forEach(function(e){var t={};n[e].forEach(function(e){e.options.forEach(function(e){return t[e]=null})});var o=s.oneOf(e,Object.getOwnPropertyNames(t));n[e].forEach(function(e){for(var t=e.node.children,n=0;n<t.length;n++){var r=t.item(n);c(r)!==o&&r.remove()}})})}},{".":2}],2:[function(e,t,n){"use strict";var r=this&&this.__awaiter||function(i,s,u,a){return new(u||(u=Promise))(function(e,t){function n(e){try{o(a.next(e))}catch(e){t(e)}}function r(e){try{o(a.throw(e))}catch(e){t(e)}}function o(t){t.done?e(t.value):new u(function(e){e(t.value)}).then(n,r)}o((a=a.apply(i,s||[])).next())})},s=this&&this.__generator||function(n,r){var o,i,s,e,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(s=i[2&t[0]?"return":t[0]?"throw":"next"])&&!(s=s.call(i,t[1])).done)return s;switch(i=0,s&&(t=[0,s.value]),t[0]){case 0:case 1:s=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,i=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(s=0<(s=u.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){u.label=t[1];break}if(6===t[0]&&u.label<s[1]){u.label=s[1],s=t;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(t);break}s[2]&&u.ops.pop(),u.trys.pop();continue}t=r.call(n,u)}catch(e){t=[6,e],i=0}finally{o=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};Object.defineProperty(n,"__esModule",{value:!0});var i=e("./html"),o=!0;function u(e){return"https://2vyiuehl9j.execute-api.us-east-2.amazonaws.com/prod/"+e}var a={appKey:"",experiments:{},defaultCompletions:{},queuedCompletedExperiments:{},queuedStartedExperiments:{}};function p(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o&&console.log.apply(console,["AUTOTUNE"].concat(e))}function c(e){var t=this;void 0!==a.startExperimentsTimer&&(clearTimeout(a.startExperimentsTimer),a.startExperimentsTimer=void 0),a.queuedStartedExperiments[e.name]=e,a.startExperimentsTimer=setTimeout(function(){return r(t,void 0,void 0,function(){var o,i;return s(this,function(e){switch(e.label){case 0:t=a.queuedStartedExperiments,n=function(e){return{options:e.options,pick:e.pick}},r={},Object.getOwnPropertyNames(t).forEach(function(e){return r[e]=n(t[e],e)}),p("Starting experiments",o=r),a.queuedStartedExperiments={},a.startExperimentsTimer=void 0,e.label=1;case 1:return e.trys.push([1,3,,4]),[4,l("POST",u("/startExperiments"),{appKey:a.appKey,experiments:o})];case 2:return i=e.sent(),[3,4];case 3:return p("Failed to start experiments",e.sent()),[2];case 4:return void 0!==i.errorMessage?p("/startExperiments error",i):(p("/startExperiments response",i),void 0!==i&&Object.getOwnPropertyNames(i.experiments).forEach(function(e){var t=a.experiments[e];void 0!==t&&(t.key=i.experiments[e].key)})),[2]}var t,n,r})})},100)}function f(e){var t=this;void 0!==a.completeExperimentsTimer&&(clearTimeout(a.completeExperimentsTimer),a.completeExperimentsTimer=void 0),a.queuedCompletedExperiments[e.name]=e,a.completeExperimentsTimer=setTimeout(function(){return r(t,void 0,void 0,function(){var n,r;return s(this,function(e){switch(e.label){case 0:t=a.queuedCompletedExperiments,n=Object.getOwnPropertyNames(t).map(function(e){return t[e]}),a.queuedCompletedExperiments={},a.completeExperimentsTimer=void 0,r={},n.forEach(function(e){return r[e.key]={pick:e.pick,payoff:e.payoff}}),p("Completing experiments",r),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,l("POST",u("/completeExperiments"),{appKey:a.appKey,experiments:r})];case 2:return e.sent(),[3,4];case 3:return p("Failed to complete experiments",e.sent()),[3,4];case 4:return[2]}var t})})},10)}function l(r,o,i){return void 0===i&&(i=void 0),new Promise(function(e,t){if("undefined"==typeof XMLHttpRequest)return t("Not running in browser");var n=new XMLHttpRequest;n.open(r,o,!0),n.setRequestHeader("Content-Type","application/json"),n.onerror=function(){return t(n.statusText)},n.onreadystatechange=function(){4==n.readyState&&(200==n.status?e(JSON.parse(n.responseText)):t("Request failed with status "+n.status))},void 0!==i?n.send(JSON.stringify(i)):n.send()})}function m(e){var t=a.experiments[e];return void 0===t&&(t=a.experiments[e]=new d(e)),t}n.initialize=function(n){return r(this,void 0,void 0,function(){var o;return s(this,function(e){switch(e.label){case 0:p("Initialize",n),a.appKey=n,o={},e.label=1;case 1:return e.trys.push([1,3,,4]),[4,l("GET",(t=n,"https://s3.us-east-2.amazonaws.com/autotune-outcomes/"+t+".json"))];case 2:return o=e.sent(),[3,4];case 3:return p("ERROR getting outcomes",e.sent()),[3,4];case 4:return p("Got outcomes",o),Object.getOwnPropertyNames(o).forEach(function(e){if(void 0===a.experiments[e]){var t=o[e],n=t.bestOption,r=t.epsilon;a.experiments[e]=new d(e,n,r)}}),i.startHTMLExperiments(),[2,{}]}var t})})},n.experiment=m;var d=function(){function e(e,t,n){void 0===t&&(t=void 0),void 0===n&&(n=1),this.name=e,this.bestOption=t,this.epsilon=n}return e.prototype.setValueAndStartExperiment=function(e){return void 0===this.pick&&(this.pick=e,c(this)),this.pick},e.prototype.complete=function(t){return void 0===t&&(t=1),r(this,void 0,void 0,function(){return s(this,function(e){return this.payoff=t,f(this),[2]})})},e.prototype.flipCoin=function(){return"true"===this.oneOf("true","false")},e.prototype.oneOf=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return this.options=t,e=void 0===this.bestOption||Math.random()<this.epsilon?t[Math.floor(Math.random()*t.length)]:this.bestOption,this.setValueAndStartExperiment(e)},e}();n.Experiment=d,n.flipCoin=function(e){var t=m(e);return(a.defaultCompletions[e]=t).flipCoin()},n.oneOf=function(e,t){var n=m(e);return(a.defaultCompletions[e]=n).oneOf.apply(n,t)},n.complete=function(t){void 0===t&&(t=1);var n=a.defaultCompletions;Object.getOwnPropertyNames(n).forEach(function(e){return n[e].complete(t)})}},{"./html":1}]},{},[1,2])(2)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).autotune=e()}}(function(){return function i(s,u,a){function p(t,e){if(!u[t]){if(!s[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(c)return c(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=u[t]={exports:{}};s[t][0].call(o.exports,function(e){return p(s[t][1][e]||e)},o,o.exports,i,s,u,a)}return u[t].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)p(a[e]);return p}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var s=e(".");function p(e){for(var t=0,n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t&=t}return t}function c(e){return e.getAttribute("option")||p(e.outerHTML).toString()}n.startHTMLExperiments=function(){var i=function(){for(var e={},t=document.querySelectorAll("[data-experiment]"),n=0;n<t.length;n++){var r=t.item(n),o=r.getAttribute("data-experiment"),i=r.getAttribute("data-option"),s=e[o];void 0===s&&(s=e[o]={options:[],nodes:[]}),-1===s.options.indexOf(i)&&s.options.push(i),s.nodes.push(r)}return e}(),n=function(){for(var e={},t=document.getElementsByTagName("autotune"),n=0;n<t.length;n++){for(var r=t.item(n),o=r.getAttribute("experiment")||p(r.innerHTML).toString(),i={node:r,options:[]},s=0;s<r.children.length;s++){var u=r.children.item(s);i.options.push(c(u))}var a=e[o]||[];a.push(i),e[o]=a}return e}();Object.getOwnPropertyNames(i).forEach(function(e){var t=i[e],n=t.options,r=t.nodes,o=s.oneOf(e,n);r.forEach(function(e){e.getAttribute("data-option")!==o&&e.remove()})}),Object.getOwnPropertyNames(n).forEach(function(e){var t={};n[e].forEach(function(e){e.options.forEach(function(e){return t[e]=null})});var o=s.oneOf(e,Object.getOwnPropertyNames(t));n[e].forEach(function(e){for(var t=e.node.children,n=0;n<t.length;n++){var r=t.item(n);c(r)!==o&&r.remove()}})})}},{".":2}],2:[function(e,t,n){"use strict";var r=this&&this.__awaiter||function(i,s,u,a){return new(u||(u=Promise))(function(e,t){function n(e){try{o(a.next(e))}catch(e){t(e)}}function r(e){try{o(a.throw(e))}catch(e){t(e)}}function o(t){t.done?e(t.value):new u(function(e){e(t.value)}).then(n,r)}o((a=a.apply(i,s||[])).next())})},s=this&&this.__generator||function(n,r){var o,i,s,e,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(s=i[2&t[0]?"return":t[0]?"throw":"next"])&&!(s=s.call(i,t[1])).done)return s;switch(i=0,s&&(t=[0,s.value]),t[0]){case 0:case 1:s=t;break;case 4:return u.label++,{value:t[1],done:!1};case 5:u.label++,i=t[1],t=[0];continue;case 7:t=u.ops.pop(),u.trys.pop();continue;default:if(!(s=0<(s=u.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){u=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){u.label=t[1];break}if(6===t[0]&&u.label<s[1]){u.label=s[1],s=t;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(t);break}s[2]&&u.ops.pop(),u.trys.pop();continue}t=r.call(n,u)}catch(e){t=[6,e],i=0}finally{o=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}};Object.defineProperty(n,"__esModule",{value:!0});var i=e("./html"),o=!0;function u(e){return"https://2vyiuehl9j.execute-api.us-east-2.amazonaws.com/prod/"+e}var a={appKey:"",experiments:{},defaultCompletions:{},queuedCompletedExperiments:{},queuedStartedExperiments:{}};function p(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o&&console.log.apply(console,["AUTOTUNE"].concat(e))}function c(e){var t=this;void 0!==a.startExperimentsTimer&&(clearTimeout(a.startExperimentsTimer),a.startExperimentsTimer=void 0),a.queuedStartedExperiments[e.name]=e,a.startExperimentsTimer=setTimeout(function(){return r(t,void 0,void 0,function(){var o,i;return s(this,function(e){switch(e.label){case 0:t=a.queuedStartedExperiments,n=function(e){return{options:e.options,pick:e.pick}},r={},Object.getOwnPropertyNames(t).forEach(function(e){return r[e]=n(t[e],e)}),p("Starting experiments",o=r),a.queuedStartedExperiments={},a.startExperimentsTimer=void 0,e.label=1;case 1:return e.trys.push([1,3,,4]),[4,l("POST",u("/startExperiments"),{appKey:a.appKey,experiments:o})];case 2:return i=e.sent(),[3,4];case 3:return p("Failed to start experiments",e.sent()),[2];case 4:return void 0!==i.errorMessage?p("/startExperiments error",i):(p("/startExperiments response",i),void 0!==i&&Object.getOwnPropertyNames(i.experiments).forEach(function(e){var t=a.experiments[e];void 0!==t&&(t.key=i.experiments[e].key)})),[2]}var t,n,r})})},100)}function f(e){var t=this;void 0!==a.completeExperimentsTimer&&(clearTimeout(a.completeExperimentsTimer),a.completeExperimentsTimer=void 0),a.queuedCompletedExperiments[e.name]=e,a.completeExperimentsTimer=setTimeout(function(){return r(t,void 0,void 0,function(){var n,r;return s(this,function(e){switch(e.label){case 0:t=a.queuedCompletedExperiments,n=Object.getOwnPropertyNames(t).map(function(e){return t[e]}),a.queuedCompletedExperiments={},a.completeExperimentsTimer=void 0,r={},n.forEach(function(e){return r[e.key]={pick:e.pick,payoff:e.payoff}}),p("Completing experiments",r),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,l("POST",u("/completeExperiments"),{appKey:a.appKey,experiments:r})];case 2:return e.sent(),[3,4];case 3:return p("Failed to complete experiments",e.sent()),[3,4];case 4:return[2]}var t})})},10)}function l(r,o,i){return void 0===i&&(i=void 0),new Promise(function(e,t){if("undefined"==typeof XMLHttpRequest)return t("Not running in browser");var n=new XMLHttpRequest;n.open(r,o,!0),n.setRequestHeader("Content-Type","application/json"),n.onerror=function(){return t(n.statusText)},n.onreadystatechange=function(){4==n.readyState&&(200==n.status?e(JSON.parse(n.responseText)):t("Request failed with status "+n.status))},void 0!==i?n.send(JSON.stringify(i)):n.send()})}function m(e){var t=a.experiments[e];return void 0===t&&(t=a.experiments[e]=new d(e)),t}n.initialize=function(n){return r(this,void 0,void 0,function(){var o;return s(this,function(e){switch(e.label){case 0:p("Initialize",n),a.appKey=n,o={},e.label=1;case 1:return e.trys.push([1,3,,4]),[4,l("GET",(t=n,"https://s3.us-east-2.amazonaws.com/autotune-outcomes/"+t+".json"))];case 2:return o=e.sent(),[3,4];case 3:return p("ERROR getting outcomes",e.sent()),[3,4];case 4:return p("Got outcomes",o),Object.getOwnPropertyNames(o).forEach(function(e){if(void 0===a.experiments[e]){var t=o[e],n=t.bestOption,r=t.epsilon;a.experiments[e]=new d(e,n,r)}}),i.startHTMLExperiments(),[2]}var t})})},n.experiment=m;var d=function(){function e(e,t,n){void 0===t&&(t=void 0),void 0===n&&(n=1),this.name=e,this.bestOption=t,this.epsilon=n}return e.prototype.setValueAndStartExperiment=function(e){return void 0===this.pick&&(this.pick=e,c(this)),this.pick},e.prototype.complete=function(t){return void 0===t&&(t=1),r(this,void 0,void 0,function(){return s(this,function(e){return this.payoff=t,f(this),[2]})})},e.prototype.flipCoin=function(){return"true"===this.oneOf("true","false")},e.prototype.oneOf=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return this.options=t,e=void 0===this.bestOption||Math.random()<this.epsilon?t[Math.floor(Math.random()*t.length)]:this.bestOption,this.setValueAndStartExperiment(e)},e}();n.Experiment=d,n.flipCoin=function(e){var t=m(e);return(a.defaultCompletions[e]=t).flipCoin()},n.oneOf=function(e,t){var n=m(e);return(a.defaultCompletions[e]=n).oneOf.apply(n,t)},n.complete=function(t){void 0===t&&(t=1);var n=a.defaultCompletions;Object.getOwnPropertyNames(n).forEach(function(e){return n[e].complete(t)})}},{"./html":1}]},{},[1,2])(2)}); |
export declare type OptionValue = string; | ||
export declare function initialize(appKey: string): Promise<{}>; | ||
export declare function initialize(appKey: string): Promise<void>; | ||
export declare function experiment<T extends OptionValue>(name: string): Experiment<T>; | ||
@@ -4,0 +4,0 @@ export declare class Experiment<T extends OptionValue> { |
@@ -215,3 +215,3 @@ "use strict"; | ||
html_1.startHTMLExperiments(); | ||
return [2, {}]; | ||
return [2]; | ||
} | ||
@@ -218,0 +218,0 @@ }); |
{ | ||
"name": "autotune", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "Automatically tune JavaScript apps", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,2 +13,23 @@ # autotune: automatic A/B testing for any app | ||
### Main title | ||
Arguing with colleagues about what title to use for the homepage? Let Autotune pick the one that converts the most users: | ||
```html | ||
<!-- Place a few options between <autotune> tags. --> | ||
<autotune> | ||
<h1>We're here to revolutionize the healthcare industry with blockchain-based nursing.</h1> | ||
<h1>We're here to revolutionize location-based news aggregation with proximity drones.</h1> | ||
<h1>We're here to revolutionize meme aggregation and delivery with AI-based CDNs.</h1> | ||
</autotune> | ||
<!-- Indicate a desirable outcome with autotune attributes. --> | ||
<a href="/signup" autotune>Sign up</a> | ||
<!-- Load the autotune library and suggestions that autotune has learned so far. --> | ||
<script src="//js.autotune.xyz/11397F73-FF90-4831-B7F7-85023F1741E4.js"></script> | ||
``` | ||
Autotune will test the options you've given between `<autotune>` tags, and automatically favor the option that gets most users to click `Sign up`. | ||
### "Log in" or "Sign in"? | ||
@@ -15,0 +36,0 @@ |
Sorry, the diff of this file is not supported yet
66583
92