Skip to content

Instantly share code, notes, and snippets.

@astfarias
Created September 16, 2017 21:32
Show Gist options
  • Save astfarias/9f6d8c1e0ef469c36c519f469f024571 to your computer and use it in GitHub Desktop.
Save astfarias/9f6d8c1e0ef469c36c519f469f024571 to your computer and use it in GitHub Desktop.
AIDAX Basic integration using just a pure HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Experimento AIDAX</title>
</head>
<body>
<h1>Experimento AIDAX</h1>
<script type="text/javascript" id="script">
var AIDAX_CLIENT_KEY="YOUR-KEY",
cookie_enabled=function(){return document.cookie="tcax",-1!==document.cookie.indexOf("tcax")};window.ax=window.ax||function(){return window.ax.factory("event").apply(this,arguments)},window.ax.methods=["on","once","user","query","session","event","delete_tags","increment","whois","ready","toggle_debug"],window.ax._container=[],window.ax.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);return window.ax._container.unshift({method:e,args:t}),window.ax}};var cookie={set:function(e,t,r,i,n){var o=new Date,a="",c=typeof t,s="",d="";i=i||"/",r&&(o.setTime(o.getTime()+24*r*60*60*1e3),a="; expires="+o.toUTCString()),s="object"===c&&"undefined"!==c?encodeURIComponent(JSON.stringify({v:t})):encodeURIComponent(t),n&&(d="; secure"),document.cookie=e+"="+s+a+"; path="+i+d},get:function(e){for(var t=e+"=",r=document.cookie.split(";"),i="",n="",o={},a=0;a<r.length;a++){for(var c=r[a];" "==c.charAt(0);)c=c.substring(1,c.length);if(0===c.indexOf(t)){if(i=decodeURIComponent(c.substring(t.length,c.length)),n=i.substring(0,1),"{"==n)try{if(o=JSON.parse(i),"v"in o)return o.v}catch(s){return i}if("undefined"==i)return;return i}}return null},remove:function(e){this.set(e,"",-1)}};window.ax.is_unique=function(){return!cookie.get("aidax_unique")},window.ax.clear_ab=function(e){if(e){if("string"==typeof e&&""!==e){var t=cookie.get("aidax_ab");if(t){var r=JSON.parse(t);delete r[e],cookie.set("aidax_ab",JSON.stringify(r),3,"/")}}}else cookie.remove("aidax_ab")},window.ax.ab=function(e,t){if("string"==typeof e&&""===e&&"object"==typeof t&&Array.isArray(t)){var r,i=cookie.get("aidax_ab"),n={},o=function(e,t){return Math.floor(Math.random()*(t-e+1))+e},a=function(){var i,a,c=[],s=0,d=0;if(Array.isArray(t))r=t[Math.floor(Math.random()*t.length)];else{for(var u in t)t.hasOwnProperty(u)&&(c.push([u,[0===d?d:d+1,r[u]+d]]),d=r[u],s+=+r[u]);for(a=o(0,s),c.sort(function(e,t){return e[1]-t[1]}),i=0;i<c.length;i++)if(a>=c[i][1][0]&&a<=c[i][1][1]){r=c[i][0];break}}n[e]=r};if(i){if(n=JSON.parse(i),n[e])return n[e];a()}else a();return cookie.set("aidax_ab",JSON.stringify(n),30,"/"),r}throw"[AIDAX] Missing ab parameters."};for(var i=0;i<window.ax.methods.length;i++){var method=window.ax.methods[i];window.ax[method]=window.ax.factory(method)}var script=document.createElement("script");script.type="text/javascript",script.async=!0,script.src="//api.aidax.com.br/aidax.js";var firstScript=document.getElementsByTagName("script")[0];firstScript.parentNode.insertBefore(script,firstScript);
</script>
<script>
ax.ready(function() { //Executa quando AIDAX carrega totalmente
console.log("AIDAX foi carregado!");
});
ax.toggle_debug(); //Mostra capturas no console
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment