-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.min.js
1 lines (1 loc) · 8.58 KB
/
track.min.js
1
"use strict";window.abRedirecting=!1,window._init&&(window.howuku=window._init);var userAgent=navigator.userAgent;!function(t,e){var n=t=>{return new URL(window.location.href).searchParams.get(t)||""},o=t=>{return t.replace(/\#[0-9]/,function(t){return t.replace("#","#\\3")}).replace(/\.[0-9]/,function(t){return t.replace(".",".\\3")})},a=(t,e,n,o)=>{var a=new XMLHttpRequest;a.open(e,t,!0),a.setRequestHeader("Content-Type","application/json;charset=UTF-8"),a.onreadystatechange=function(){this.readyState===XMLHttpRequest.DONE&&200===this.status&&o(a.responseText)},a.send(JSON.stringify(n))};window.startAbTest=(t=>{localStorage.setItem("_abcache",t);let e=(t,e)=>{let n=null;if("string"==typeof t)try{t=JSON.parse(t)}catch(t){return null}return t&&t[e]&&(t[e].vaId||0===t[e].vaId)&&(n=t[e].vaId),n};let a=async(t,e,n,o,a=null,r)=>{""===n&&(n="-1");let i=0;function l(t){try{return!(0===Object.keys(t).length&&t.constructor===Object)}catch(t){return!1}}let c=!1,d=[];window.location.href.includes("howuku.com")&&console.log("window.abdata",window.abdata);for(let t=0;t<window.abdata.length;t++)if(l(window.abdata[t].condition)){window.location.href.includes("howuku.com")&&console.log("has condition",window.abdata[t].condition),c=!0;let e=window.abdata[t].condition;if(e.url)for(let n=0;n<e.url.length;n++)if(window.location.href.toString().includes(e.url[n])){d.push(window.abdata[t].name);break}if(e.referrer)for(let n=0;n<e.referrer.length;n++)if(document.referrer.toString().includes(e.referrer[n])){d.push(window.abdata[t].name);break}if(e.preferred_country)for(let n=0;n<e.preferred_country.length;n++)if(a===e.preferred_country[n]){d.push(window.abdata[t].name);break}if(e.showToAll&&!0===e.showToAll){d.push(window.abdata[t].name);break}}if(!c)for(let t=0;t<window.abdata.length;t++)d.push(window.abdata[t].name);var u=d;c||u.push("-1"),0===Number(n)&&(n="-1");var s=u.indexOf(n);!c&&s>=0&&u.splice(s,1);let w,h=function(t,e=100){return function(t){const e=BigInt("0x"+t);let n=Number(e%BigInt(Number.MAX_SAFE_INTEGER));const o=Math.random;Math.random=function(){const t=1e4*Math.sin(n++);return t-Math.floor(t)};const a=(r=1,i=101,Math.floor(Math.random()*(i-r)+r));var r,i;return Math.random=o,a}(t)<=e}(await async function(){const t=`${navigator.userAgent}${navigator.language}${Intl.DateTimeFormat().resolvedOptions().timeZone}${window.screen.height}${window.screen.width}${window.screen.colorDepth}${navigator.platform}`;return await async function(t){const e=(new TextEncoder).encode(t),n=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(n)).map(t=>t.toString(16).padStart(2,"0")).join("")}(t)}(),Number(r));window.location.href.includes("howuku.com")&&console.log("Experiment allocation isAllowed?"),window.location.href.includes("howuku.com")&&console.log(h),h&&(w=1===u.length?u[0]:window.isMAB?function(t,e=1,n=.05){function o(t,e){return t[e].convert/(t[e].count||1)}const a=t.reduce((t,e)=>t+e.count,0),r=e/Math.sqrt(n*a+1);if(Math.random()<r)return t[Math.floor(Math.random()*t.length)].name;{let e=0;for(let n=1;n<t.length;n++)o(t,n)>o(t,e)&&(e=n);return t[e].name}}(e):u[~~((t=>e=>(2**31-1&(t=Math.imul(16807,t)))/2**31)((t=>Math.imul(t,2654435761)>>>0)(t))()*u.length)]);let m=null;for(let t in window.abdata)if(window.abdata[t].name===w){i=window.abdata[t].name,m=window.abdata[t].data;break}let f={};try{localStorage.getItem("_variant_result")&&(f=JSON.parse(localStorage.getItem("_variant_result")))}catch(t){}try{f&&(f[o]||(f[o]={vaId:i}),window.vaId=JSON.stringify(f),localStorage.setItem("_variant_result",JSON.stringify(f)))}catch(t){}};function r(t){var e=t.parentNode;return(t.scrollTop||e.scrollTop)/(e.scrollHeight-e.clientHeight)*100}let i=null;try{i=JSON.parse(t)}catch(t){}if(t&&i){function l(t){return"string"==typeof t?t.replace(/^www\./g,"").replace(/\/$/g,""):t}for(let t=0;t<i.length;t++){let b=i[t],v=b.test_id,_=new URLSearchParams(window.location.search),k=_.get("test-preview")||null,S=_.get("test-variant")||null;if((!k||Number(v)===Number(k))&&(k&&Number(v)===Number(k)&&console.log("preview id",v),b)){var c=window.location.hostname+window.location.pathname;if("pageview"===b.goal_type){var d=document.createElement("a");d.href=b.goal_value,l(c)===l(d.hostname+d.pathname)&&window.howuku.converted(b.test_key).then(function(){console.log("converted - page visited!")})}if("scrolling"===b.goal_type){let t=b.goal_value,e=!1;document.onscroll=(()=>{var n=r(document.body);Math.round(n)>=Number(t)&&!e&&(e=!0,window.howuku.converted(b.test_key).then(function(){console.log("converted - scrolled!")}))})}if("duration"===b.goal_type){let t=b.goal_value;setTimeout(()=>{window.howuku.converted(b.test_key).then(function(){console.log("converted - stayed for longer than "+t+" seconds!")})},1e3*t)}var u=document.createElement("a");u.href=b.element_url;let t={};try{t=JSON.parse(b.data)}catch(t){}let i=[],v="";try{Object.keys(t).forEach(function(e){v=e;let n=t[e];for(let t=0;t<n.length;t++)if(n[t].data.length){let e=n[t].data[0];e&&e.url&&i.push(e.url)}})}catch(t){console.error(t)}let _=((t,e)=>{for(let n=0;n<e.length;n++){let o=e[n],a=document.createElement("a");if(a.href=o,l(t)===l(a.hostname+a.pathname))return!0}return!1})(c,i);if(l(c)===l(u.hostname+u.pathname)||_){if("clickOnElement"===b.goal_type){let t=document.querySelector(o(b.goal_value));console.log("goal to click on element",t);let e=!1;setTimeout(()=>{t&&t.addEventListener("click",function(n){e||(n.preventDefault(),console.log("goal clicked",b.test_key),window.howuku.converted(b.test_key).then(function(){e=!0,console.log("goal completed",b.test_key),t.click()}))})},4e3)}if("formSubmit"===b.goal_type){let t=document.querySelector(o(b.goal_value));setTimeout(()=>{t&&t.addEventListener("submit",function(e){e.preventDefault(),window.howuku.converted(b.test_key).then(function(){t.submit()})})},4e3)}}var s=window.location.protocol+"//"+window.location.hostname+window.location.pathname,w=window.location.protocol+"//www."+window.location.hostname+window.location.pathname;let k=!1;try{let t=JSON.parse(b.data);k=t[s]||t[s.replace(/\/+$/,"")]||t[w]||t[w.replace(/\/+$/,"")]}catch(t){}if(k&&(window.abdata=k),!k)continue;let A=!b.is_ab;var h=null;let M=null,T=null,N=null,E=e(window.vaId,b.test_id);if(S&&(E=S),null===E||A){try{b.result=JSON.parse(b.result)}catch(t){}a(b.seed,b.result,b.last_variant,b.test_id,b.user_data.country_code,b.traffic_allocation)}var m=e(window.vaId,b.test_id);if(S&&(m=S),m){var f=null;for(let t in window.abdata)if(window.abdata[t].name===m){f=window.abdata[t].data,M=window.abdata[t].customCSS,T=window.abdata[t].customJS;break}f&&(h=f)}if(h){function g(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/\//g,"/")}function p(t){return t.replace(/{{(([ ]+)?[a-z0-9_-]+([ ]+)?)}}/gi,function(t,e){return g(n(e.trim()))})}function y(t,e=null){return e?t.replace(/{{(([ ]+)?(country|city|country_flag)([ ]+)?)}}/gi,function(t,n){return g(e[n.trim()]||"")}):t}for(let t=0;t<h.length;t++){h[t].url&&(window.abRedirecting=!0,N=h[t].url,window.location.href=N);try{let e=document.querySelectorAll(h[t].target)[h[t].index];e&&h[t].textContent&&(e.textContent=h[t].textContent),e&&h[t].innerHTML&&(e.innerHTML=p(y(h[t].innerHTML.replace(/\&\#039\;/g,"'").replace(/\&\#034\;/g,'"'),b.user_data))),e&&h[t].src&&(e.src=h[t].src),e&&e instanceof HTMLElement&&h[t].style&&e.setAttribute("style",h[t].style),e&&e instanceof HTMLElement&&h[t].class&&e.setAttribute("class",h[t].class)}catch(t){console.error(t)}}}if(M){if(!document.getElementById("howu-custom-style-id")){let t=document.createElement("style");t.setAttribute("id","howu-custom-style-id"),t.setAttribute("type","text/css"),t.innerHTML=M,document.head.appendChild(t)}}if(T){if(!document.getElementById("howu-custom-script-id")){let t=document.createElement("script"),e=document.createTextNode(T);t.setAttribute("id","howu-custom-script-id"),t.setAttribute("type","text/javascript"),t.appendChild(e),document.body.appendChild(t)}}}}}window.abRedirecting||(document.body.style.opacity=1)});var r=function(){const t=function(){let t=document.getElementsByTagName("script"),e=0;for(;e<t.length;e++){let n=t[e];if(/(track\.min\.js)/.test(n.getAttribute("src"))&&n.getAttribute("key"))return n}}();window._H_CDN_URL=t.src?t.src.split("/")[2]:"";let e=localStorage.getItem("_abcache");e&&window.startAbTest(e),localStorage.removeItem("_abcache");let n={k:t.getAttribute("key"),h:window.location.host};a("https://api.howuku.com/widget/test","POST",n,t=>{try{"[]"!==t?window.startAbTest(t):document.body.style.opacity=1}catch(t){}})};"interactive"===e.readyState||"complete"===e.readyState||"loaded"===e.readyState?r():e.addEventListener("DOMContentLoaded",r)}(window,document);