-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathEqatecMonitor.min.js
executable file
·30 lines (30 loc) · 14.6 KB
/
EqatecMonitor.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function(k){function z(b){var a=!1,f="",e=0,d=1,g={},h=[],i=[],l=function(a){if(c.isString(a)){var f=c.trim(c.asString(a));if(f){if(c.stringTooLong(b,f,1E3))return null;var a="eq_"+a,e=g[a];e||(e={featureName:f,sessionHitCount:0,timingStart:0},g[a]=e);return e}return null}};return{addFeatureUsage:function(a){if(a=l(a))a.sessionHitCount+=1,d++},startFeatureTiming:function(a){if((a=l(a))&&!(0<a.timingStart))a.timingStart=c.getTimeStamp()},endFeatureTiming:function(a){if((a=l(a))&&0!==a.timingStart){var b=
c.getTimeStamp(),f=b-a.timingStart;a.timingStart=0;h.push({name:a.featureName,value:f,type:1,runtime:b-e});d++}},cancelFeatureTiming:function(a){if(a=l(a))a.timingStart=0},addFeatureValue:function(a,b){var f=c.trim(c.asString(a));if(f&&c.isNumber(b)){var g=c.getTimeStamp();h.push({name:f,value:c.toNumber(b),type:0,runtime:g-e});d++}},addException:function(a,f){if(a){var g=c.asString(f),h=c.getTimeStamp(),l="",k=a.name||typeof a,n=a.message||a.name||"";try{l=c.stackTrace({e:a})}catch(m){c.error(b,
"could not format stacktrace: "+m.message)}10<i.length&&(c.logMessage(b,"removing oldest exception"),i.pop());i.push({type:k,message:n,runtime:h-e,info:g,stacktrace:l});d++}},setInstallationID:function(a){if(!c.stringTooLong(b,a,50)&&(a=c.asString(a)))f=a,d++},clear:function(){i=[];h=[]},getPayload:function(){var b=[],c;for(c in g)if(g.hasOwnProperty(c)){var e=g[c];e.sessionHitCount&&(b.push({name:e.featureName,sessionHitCount:e.sessionHitCount}),e.sessionHitCount=0)}return{installationId:f,stopped:a?
"0":"1",features:b,exceptions:i,featurevalues:h}},startTime:e,version:function(){return d},startSession:function(b){e=b;a=!0},stopSession:function(){a=!1}}}var c={isFunction:function(b){return b&&"function"===typeof b},callIfFunction:function(b){try{c.isFunction(b)&&b()}catch(a){}},isString:function(b){return b&&"string"===typeof b},asString:function(b){var a="";b&&(a=c.isFunction(b)?c.asString(b()):b.toString());return a},trim:function(b){return b?!String.prototype.trim?b.replace(/^\s\s*/,"").replace(/\s\s*$/,
""):b.trim():""},getClientTimestamp:function(){var b=!Date.now?(new Date).getTime():Date.now(),a=6E4*(new Date).getTimezoneOffset(),b=b-a;return b===c._clientTimeBarrier?(c._clientTimeBarrier++,c._clientTimeBarrier):c._clientTimeBarrier=b},_clientTimeBarrier:0,getTimeStamp:function(){var b=(new Date).getTime();return b===c._timestampBarrier?b+1:b},getTimeStampBarrier:function(){c._timestampBarrier=c.getTimeStamp();return c._timestampBarrier},_timestampBarrier:0,isNumber:function(b){return!isNaN(parseInt(b))&&
isFinite(b)},toNumber:function(b){return parseInt(b)},parseURL:function(b){for(var a="source protocol authority userInfo user password host port relative path directory file query anchor".split(" "),c={},e=14,b=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(b);e--;)c[a[e]]=b[e]||"";return c},getServerUri:function(b,a,f,e){if(f&&c.isString(f))try{var d=
c.parseURL(f);if(d&&d.host)return(d.protocol?d.protocol+"://":"//")+d.host+(d.port?":"+d.port:"")+"/json.ashx";c.log(b,"Could not parse serverUri to valid format:"+f)}catch(g){c.log(b,"unable to parse serverUri to valid format:"+f)}"undefined"===typeof e?(b="https",k&&(k.location&&"https:"!==k.location.protocol)&&(b="http")):b=e?"https":"http";return b+"://"+a+".monitor-eqatec.com/json.ashx"},log:function(b,a){try{b&&(c.isFunction(b.logMessage)&&a&&c.isString(a))&&b.logMessage(a)}catch(f){}},error:function(b,
a){try{b&&(c.isFunction(b.logError)&&a&&c.isString(a))&&b.logError(a)}catch(f){}},getInfo:function(b){var a=k.navigator,f=k.screen,e=k.document,d={};f&&(d.screen=f.width+"x"+f.height,d.depth=f.colorDepth+"-bit");if(a&&(a=a.language||a.userLanguage))d.language=a.toLowerCase();if(e){d.characterSet=e.characterSet||e.charset||"-";try{var g=e.documentElement,h=e.body,i=h&&h.clientWidth&&h.clientHeight,a=[];g&&(g.clientWidth&&g.clientHeight&&("CSS1Compat"===e.compatMode||!i)?a=[g.clientWidth,g.clientHeight]:
i&&(a=[h.clientWidth,h.clientHeight]));d.clientsize=a.join("x")}catch(l){c.error(b,"Unable to read browser info: "+l.message)}}return d},generateId:function(){for(var b=void 0,a=void 0,a=b="";36>b++;a+=51*b&52?(b^15?8^Math.random()*(b^20?16:4):4).toString(16):"-");return a},setCookie:function(b,a,f,e,d){var g=document;g&&(b=b+"="+a+";path="+f+";",e&&0<e&&(e=new Date(c.getTimeStamp()+e),b+="expires="+e.toUTCString()+";"),d&&(b+="domain="+d+";"),g.cookie=b)},getCookie:function(b){var a=document.cookie.split(";"),
f;for(f=0;f<a.length;f++){var e=a[f].split("=");if(2==e.length){var d=c.trim(e[0]);if(b===d)return c.trim(e[1])}}return null},parseCookieStringToLiteral:function(b){if(b&&(b=b.split("."),2==b.length))return{first:b[0],second:b[1]}},setTimeout:function(b,a){try{if(c.isFunction(b)&&c.isNumber(a))return k.setTimeout(b,c.toNumber(a))}catch(f){}return 0},clearTimeout:function(b){try{c.isNumber(b)&&k.clearTimeout(b)}catch(a){}},cookiesEnabled:function(){try{var b=k.navigator||{},a=b.cookieEnabled?!0:!1;
"undefined"==typeof b.cookieEnabled&&!a&&(document.cookie="testcookie",a=-1!=document.cookie.indexOf("testcookie")?!0:!1);return a}catch(c){}return!1},trackingDisabled:function(){return!1},stringTooLong:function(b,a,f){return!c.isString(a)||!c.isNumber(f)?!0:c.asString(a).length>f?(c.error(b,"Input is too long: "+a),!0):!1}};(function(){function b(a){return 10>a?"0"+a:a}function a(a){d.lastIndex=0;return d.test(a)?'"'+a.replace(d,function(a){var b=i[a];return"string"===typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+
'"':'"'+a+'"'}function f(b,c){var e,d,i,k,n=g,m,j=c[b];j&&"object"===typeof j&&"function"===typeof j.toJSON&&(j=j.toJSON(b));"function"===typeof l&&(j=l.call(c,b,j));switch(typeof j){case "string":return a(j);case "number":return isFinite(j)?""+j:"null";case "boolean":case "null":return""+j;case "object":if(!j)return"null";g+=h;m=[];if("[object Array]"===Object.prototype.toString.apply(j)){k=j.length;for(e=0;e<k;e+=1)m[e]=f(e,j)||"null";i=0===m.length?"[]":g?"[\n"+g+m.join(",\n"+g)+"\n"+n+"]":"["+
m.join(",")+"]";g=n;return i}if(l&&"object"===typeof l){k=l.length;for(e=0;e<k;e+=1)"string"===typeof l[e]&&(d=l[e],(i=f(d,j))&&m.push(a(d)+(g?": ":":")+i))}else for(d in j)Object.prototype.hasOwnProperty.call(j,d)&&(i=f(d,j))&&m.push(a(d)+(g?": ":":")+i);i=0===m.length?"{}":g?"{\n"+g+m.join(",\n"+g)+"\n"+n+"}":"{"+m.join(",")+"}";g=n;return i;default:return""+j}}var e;e||(e={});"function"!==typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+
"-"+b(this.getUTCMonth()+1)+"-"+b(this.getUTCDate())+"T"+b(this.getUTCHours())+":"+b(this.getUTCMinutes())+":"+b(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,g,h,i={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},l;"function"!==typeof e.stringify&&
(e.stringify=function(a,b,c){var e;h=g="";if("number"===typeof c)for(e=0;e<c;e+=1)h+=" ";else"string"===typeof c&&(h=c);if((l=b)&&"function"!==typeof b&&("object"!==typeof b||"number"!==typeof b.length))throw Error("JSON.stringify");return f("",{"":a})});c.encodeJSON=e.stringify})();(function(){function b(a){a=a&&a.e?a.e:null;return(new b.implementation).run(a)}b.implementation=function(){};b.implementation.prototype={run:function(a){if(!a)return"";var b;if(!(b=a))b=void 0;a=b;b=this._mode||this.mode(a);
return"other"===b?this.other(arguments.callee):this[b](a)},mode:function(a){return a.arguments?this._mode="chrome":k.opera&&a.stacktrace?this._mode="opera10":a.stack?this._mode="firefox":k.opera&&!("stacktrace"in a)?this._mode="opera":this._mode="other"},chrome:function(a){return a.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@").split("\n")},firefox:function(a){return a.stack.replace(/(?:\n@:0)?\s+$/m,"").replace(/^\(/gm,"{anonymous}(").split("\n")},
opera10:function(a){var a=a.stacktrace.split("\n"),b=/.*line (\d+), column (\d+) in ((<anonymous function\:?\s*(\S+))|([^\(]+)\([^\)]*\))(?: in )?(.*)\s*$/i,c,d,g;c=2;d=0;for(g=a.length;c<g-2;c++)if(b.test(a[c])){var h=RegExp.$6+":"+RegExp.$1+":"+RegExp.$2,i=RegExp.$3,i=i.replace(/<anonymous function\:?\s?(\S+)?>/g,"{anonymous}");a[d++]=i+"@"+h}a.splice(d,a.length-d);return a},opera:function(a){var a=a.message.split("\n"),b=/Line\s+(\d+).*script\s+(http\S+)(?:.*in\s+function\s+(\S+))?/i,c,d,g;c=4;
d=0;for(g=a.length;c<g;c+=2)b.test(a[c])&&(a[d++]=(RegExp.$3?RegExp.$3+"()@"+RegExp.$2+RegExp.$1:"{anonymous}()@"+RegExp.$2+":"+RegExp.$1)+" -- "+a[c+1].replace(/^\s+/,""));a.splice(d,a.length-d);return a},other:function(a){for(var b=/function\s*([\w\-$]+)?\s*\(/i,c=[],d=0,g,h;a&&10>c.length;){g=b.test(a.toString());h=[];try{h=Array.prototype.slice.call(a.arguments),a=a.caller}catch(i){a=null}g=g?RegExp.$1||"{anonymous}":"{anonymous}";c[d++]=g+"("+this.stringifyArguments(h)+")";if(!a)break}return c},
stringifyArguments:function(a){for(var b=0;b<a.length;++b){var c=a[b];void 0===c?a[b]="undefined":null===c?a[b]="null":c.constructor&&(c.constructor===Array?a[b]=3>c.length?"["+this.stringifyArguments(c)+"]":"["+this.stringifyArguments(Array.prototype.slice.call(c,0,1))+"..."+this.stringifyArguments(Array.prototype.slice.call(c,-1))+"]":c.constructor===Object?a[b]="#object":c.constructor===Function?a[b]="#function":c.constructor===String&&(a[b]='"'+c+'"'))}return a.join(",")}};c.stackTrace=b})();
var t=k._eqatec||{};k._eqatec=t;t.createMonitor=function(b){var a=0,f="",e=!1,d={logError:function(){},logMessage:function(){}},g=0,h=!1,i=!1,l=0,t="",r="",w="",s={},x=!1,u=!0,n=!1,m=void 0,j=!1,y="",o={};try{b=b||{},f=c.trim(c.asString(b.productId))||"",d=b.loggingInterface||d,w=b.version,s=b.location||{},x=c.cookiesEnabled()&&b.useCookies,u=b.useHttps,m=b.userAgent,n=b.testMode,j=c.trackingDisabled(),y=c.getServerUri(d,f,b.serverUri,u),o=z(d),(32>f.length||36<f.length)&&c.error(d,"Invalid productId assigned, expecting between 32 and 36 characters: "+
f)}catch(C){c.log(d,"failed while initializing monitor")}var q=function(a){try{!e&&!a?c.log(d,"monitor not started"):h&&!a?i=!0:(A(a),o.clear())}catch(b){c.log(d,"failed while calling forceSync")}},B=function(b){var e=c.getClientTimestamp(),h=c.getTimeStampBarrier()-a,i={version:w,monitorversion:"3.3.43",productId:f,sessionId:t,startCount:l,userId:r,runtime:h,clienttime:e,starttime:a,session:o.getPayload()};s&&(s.latitude&&s.longitude)&&(i.location=s);b.push("pv=5");b.push("mv=3.3.43");b.push("pi="+
encodeURIComponent(f));b.push("av="+encodeURIComponent(w));b.push("mt=js");b.push("ps="+(g+1));b.push("ct="+e);b.push("rt="+h);"undefined"!==typeof n&&!0===n&&b.push("tm=true");0===g&&(i.info=c.getInfo(d));return c.encodeJSON(i)},A=function(a){try{var e=!0===a?" Monitor stopped.":"";i=!1;var f,j,a=[];o.version();j=B(a);var l="?"+a.join("&"),l=y+l,p;b.xmlHttpRequest?p=b.xmlHttpRequest:XMLHttpRequest&&(xhrRequest=new XMLHttpRequest,"withCredentials"in xhrRequest&&void 0!==xhrRequest.withCredentials&&
(p=xhrRequest));p&&(c.isFunction(p.setTimeout)&&p.setTimeout(3E4),p.open("POST",l,!0),p.setRequestHeader("Content-Type","text/plain"),m&&p.setRequestHeader("User-Agent",m),p.onreadystatechange=function(){try{if(4==p.readyState){h=false;var a=c.asString(p.status);if(a.indexOf("2")===0){g++;c.log(d,"Statistics was sent successfully (xhr)."+e)}else c.log(d,"Statistics failed to be sent: "+a);i&&q()}}catch(b){c.error(d,"failed to handle server reply")}},f=p);void 0!==k.XDomainRequest&&void 0===f&&(f=
new k.XDomainRequest,f.open("POST",l),f.onprogress=function(){},f.onerror=function(){h=false;c.log(d,"Statistics failed to be sent. (XDomainRequest error)")},f.onload=function(){g++;h=false;c.log(d,"Statistics was sent successfully (xdr)."+e);i&&q()},f.ontimeout=function(){h=false;c.log(d,"Statistics failed to be sent. Timeout")});f&&j?(f.send(j),h=!0):c.log(d,"Statistics failed to be sent. No valid request object could be created.")}catch(n){c.error(d,"failed to send data:"+n.message)}},u={start:function(){try{if(!e&&
!j){var b="",h=r||"",i=1,k=c.getTimeStampBarrier();if(x){var m=!1,p=function(){b=c.generateId(f);m=!0;n=b+"."+k;c.setCookie("__eqtSession"+f,n,"/",0,"")},n=c.getCookie("__eqtSession"+f),v=c.parseCookieStringToLiteral(n);if(v){var b=v.first,s=parseInt(v.second);864E5<k-s?p():k=s}else p();var u=c.getCookie("__eqtUser"+f);(v=c.parseCookieStringToLiteral(u))?(h=v.first||c.generateId(f),i=parseInt(v.second)+(m?1:0)):(h=c.generateId(f),i=1);c.setCookie("__eqtUser"+f,h+"."+i,"/",31536E6,"")}t=b||c.generateId(f);
r=h;l=i;a=k;o.startSession(a);g=0;o.clear();e=!0;c.log(d,"monitor has started, connecting to "+y);q()}}catch(w){c.log(d,"failed while calling start. "+w.description)}},stop:function(){try{e&&!j&&(x&&c.setCookie("__eqtSession"+f,""),o.stopSession(),q(!0),e=!1,c.log(d,"monitor has stopped"))}catch(a){c.log(d,"failed while calling stop")}},setInstallationID:function(a){try{o.setInstallationID(a),q()}catch(b){c.log(d,"failed while calling setInstallationID")}},setUserID:function(a){try{r?c.logMessage(d,
"UserID has already been assigned"):a&&((r=c.asString(a))&&(32>r.length||36<r.length)&&c.log(d,"Invalid UserId assigned, expecting GUID instead of "+r),q())}catch(b){c.log(d,"failed while calling setUserID")}},trackFeature:function(a){try{e?(o.addFeatureUsage(a),q()):c.log(d,"Monitor is not started")}catch(b){c.log(d,"failed while calling trackFeature")}},trackException:function(a,b){try{e&&(o.addException(a,b),q())}catch(f){c.log(d,"failed while calling trackException")}},trackFeatureValue:function(a,
b){try{e&&(o.addFeatureValue(a,b),q())}catch(f){c.log(d,"failed while calling trackFeatureValue")}},trackFeatureStart:function(a){try{e&&o.startFeatureTiming(a)}catch(b){c.log(d,"failed while calling trackFeatureStart")}},trackFeatureStop:function(a){try{e&&(o.endFeatureTiming(a),q())}catch(b){c.log(d,"failed while calling trackFeatureStop")}},trackFeatureCancel:function(a){try{e&&o.cancelFeatureTiming(a)}catch(b){c.log(d,"failed while calling trackFeatureCancel")}},status:function(){return{payloads:g,
isStarted:e,cookieId:r,isDisabled:j}}};k._eqatecDebug&&(u.statisticsContainer=o);return u};t.createSettings=function(b){return{productId:b,serverUri:"",loggingInterface:void 0,version:"0.0.0.0",useCookies:!0,useHttps:void 0,testMode:!1,userAgent:void 0,xmlHttpRequest:void 0,location:{latitude:"",longitude:""}}};t.createTraceLogger=function(){var b=function(a,b){console&&(console.log&&c.isFunction(console.log)&&b)&&console.log(a+b)};return{logMessage:function(a){b("",a)},logError:function(a){b("Error: ",
a)}}};k._eqatecDebug&&(t.eqatecUtil=c)})("undefined"!==typeof window&&null!==window?window:"undefined"!==typeof global&&null!==global?global:{});