blob: 7bf23c037bb7c580a9c2ff610bbef7baeda8eb9b [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* @preserved
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).userale={})}(this,(function(e){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}var n="2.3.0",o=null;function r(e,t){var n=e.autostart,o=t.autostart;Object.keys(t).forEach((function(n){if("userFromParams"===n){var o=(r=t[n],i=new RegExp("[?&]"+r+"(=([^&#]*)|&|#|$)"),(a=window.location.href.match(i))&&a[2]?decodeURIComponent(a[2].replace(/\+/g," ")):null);o&&(e.userId=o)}var r,i,a;e[n]=t[n]})),!1!==n&&!1!==o||(e.autostart=!1)}var i=function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))},a=function(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"},s=function(e){this.version=e,this.type="node",this.name="node",this.os=process.platform},l=function(e,t,n,o){this.name=e,this.version=t,this.os=n,this.bot=o,this.type="bot-device"},u=function(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null},c=function(){this.type="react-native",this.name="react-native",this.version=null,this.os=null},d=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,f=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/]],m=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function p(e){var t=function(e){return""!==e&&f.reduce((function(t,n){var o=n[0],r=n[1];if(t)return t;var i=r.exec(e);return!!i&&[o,i]}),!1)}(e);if(!t)return null;var n=t[0],o=t[1];if("searchbot"===n)return new u;var r=o[1]&&o[1].split(".").join("_").split("_").slice(0,3);r?r.length<3&&(r=i(i([],r,!0),function(e){for(var t=[],n=0;n<e;n++)t.push("0");return t}(3-r.length),!0)):r=[];var s=r.join("."),c=function(e){for(var t=0,n=m.length;t<n;t++){var o=m[t],r=o[0];if(o[1].exec(e))return r}return null}(e),p=d.exec(e);return p&&p[1]?new l(n,s,c,p[1]):new a(n,s,c)}var h,w,g,v,y,S,b,W,O,T,k,E,N=h?p(h):"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product?new c:"undefined"!=typeof navigator?p(navigator.userAgent):"undefined"!=typeof process&&process.version?new s(process.version.slice(1)):null,I=null,x=null;function M(e,t){if(!g.on)return!1;var n=null;t&&(n=t(e));var o,r=(o=e.timeStamp&&e.timeStamp>0?g.time(e.timeStamp):Date.now(),{milli:Math.floor(o),micro:Number((o%1).toFixed(3))}),i={target:B(e.target),path:P(e),pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,browser:K(),clientTime:r.milli,microTime:r.micro,location:C(e),scrnRes:A(),type:e.type,logType:"raw",userAction:!0,details:n,userId:g.userId,toolVersion:g.version,toolName:g.toolName,useraleVersion:g.useraleVersion,sessionID:g.sessionID};return!("function"==typeof I&&!I(i))&&("function"==typeof x&&(i=x(i,e)),w.push(i),!0)}function D(e,t,n){if(!g.on)return!1;var o=null;t&&(o=t());var r={pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,browser:K(),clientTime:Date.now(),scrnRes:A(),logType:"custom",userAction:n,details:o,userId:g.userId,toolVersion:g.version,toolName:g.toolName,useraleVersion:g.useraleVersion,sessionID:g.sessionID},i=Object.assign(r,e);return!("function"==typeof I&&!I(i))&&("function"==typeof x&&(i=x(i)),w.push(i),!0)}function C(e){return null!=e.pageX?{x:e.pageX,y:e.pageY}:null!=e.clientX?{x:document.documentElement.scrollLeft+e.clientX,y:document.documentElement.scrollTop+e.clientY}:{x:null,y:null}}function A(){return{width:window.innerWidth,height:window.innerHeight}}function B(e){return e.localName?e.localName+(e.id?"#"+e.id:"")+(e.className?"."+e.className:""):e.nodeName?e.nodeName+(e.id?"#"+e.id:"")+(e.className?"."+e.className:""):e&&e.document&&e.location&&e.alert&&e.setInterval?"Window":"Unknown"}function P(e){var t=[];if(e.path)t=e.path;else for(var n=e.target;n;)t.push(n),n=n.parentElement;return function(e){var t,n=0,o=[];for(;t=e[n];)o.push(B(t)),++n;return o}(t)}function K(){return{browser:N?N.name:"",version:N?N.version:""}}var L,V=["click","focus","blur","input","change","mouseover","submit"],R=["load","blur","focus"];function X(e){return{clicks:e.detail,ctrl:e.ctrlKey,alt:e.altKey,shift:e.shiftKey,meta:e.metaKey}}function _(e){return function(e){T={click:X,dblclick:X,mousedown:X,mouseup:X,focus:null,blur:null,input:e.logDetails?function(e){return{value:e.target.value}}:null,change:e.logDetails?function(e){return{value:e.target.value}}:null,dragstart:null,dragend:null,drag:null,drop:null,keydown:e.logDetails?function(e){return{key:e.keyCode,ctrl:e.ctrlKey,alt:e.altKey,shift:e.shiftKey,meta:e.metaKey}}:null,mouseover:null},k={},E={wheel:function(e){return{x:e.deltaX,y:e.deltaY,z:e.deltaZ}},scroll:function(){return{x:window.scrollX,y:window.scrollY}},resize:function(){return{width:window.outerWidth,height:window.outerHeight}}},L={submit:null}}(e),Object.keys(T).forEach((function(e){document.addEventListener(e,(function(t){M(t,T[e])}),!0)})),V.forEach((function(e){document.addEventListener(e,(function(e){!function(e){var t=B(e.target),n=P(e),o=e.type,r=Math.floor(e.timeStamp&&e.timeStamp>0?g.time(e.timeStamp):Date.now());if(null==v&&(v=t,y=o,S=n,b=r,W=0),v!==t||y!==o){if(O={target:v,path:S,pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,browser:K(),count:W,duration:r-b,startTime:b,endTime:r,type:y,logType:"interval",targetChange:v!==t,typeChange:y!==o,userAction:!1,userId:g.userId,toolVersion:g.version,toolName:g.toolName,useraleVersion:g.useraleVersion,sessionID:g.sessionID},"function"==typeof I&&!I(O))return!1;"function"==typeof x&&(O=x(O,e)),w.push(O),v=t,y=o,S=n,b=r,W=0}v==t&&y==o&&(W+=1)}(e)}),!0)})),Object.keys(E).forEach((function(t){k[t]=!0,window.addEventListener(t,(function(n){k[t]&&(k[t]=!1,M(n,E[t]),setTimeout((function(){k[t]=!0}),e.resolution))}),!0)})),Object.keys(L).forEach((function(e){document.addEventListener(e,(function(t){M(t,T[e])}),!0)})),R.forEach((function(e){window.addEventListener(e,(function(e){M(e,(function(){return{window:!0}}))}),!0)})),!0}var j=null;function $(e,t){null!==j&&clearInterval(j),j=function(e,t){return setInterval((function(){t.on&&e.length>=t.logCountThreshold&&(H(e.slice(0),t,0),e.splice(0))}),t.transmitInterval)}(e,t),function(e,t){window.addEventListener("pagehide",(function(){e.length>0&&(navigator.sendBeacon(t.url,JSON.stringify(e)),e.splice(0))}))}(e,t)}function H(e,t,n){if("fetch"===t.sendProtocol){var o=JSON.stringify(e);fetch(t.url,{method:"POST",headers:{"Content-Type":"application/json;charset=UTF-8"},body:o}).then((function(e){return e.json()})).then((function(e){console.log("Success:",e)})).catch((function(e){console.error("Error:",e)}))}else{var r=new XMLHttpRequest,i=JSON.stringify(e);r.open("POST",t.url),t.authHeader&&r.setRequestHeader("Authorization",t.authHeader),r.setRequestHeader("Content-type","application/json;charset=UTF-8"),r.onreadystatechange=function(){4===r.readyState&&200!==r.status&&n>0&&H(e,t,n--)},r.send(i)}}var F,z={},Y=[],J=Date.now();window.onload=function(){F=Date.now()},e.started=!1,z.on=!1,z.useraleVersion=n,r(z,function(){var e={};null===o&&(o=function(e,t){if(null===window.sessionStorage.getItem(e))return window.sessionStorage.setItem(e,JSON.stringify(t)),t;return JSON.parse(window.sessionStorage.getItem(e))}("userAleSessionId","session_"+String(Date.now())));var t,n=document.currentScript||(t=document.getElementsByTagName("script"))[t.length-1],r=n?n.getAttribute.bind(n):function(){return null};return e.autostart="false"!==r("data-autostart"),e.url=r("data-url")||"http://localhost:8000",e.transmitInterval=+r("data-interval")||5e3,e.logCountThreshold=+r("data-threshold")||5,e.userId=r("data-user")||null,e.version=r("data-version")||null,e.logDetails="true"===r("data-log-details"),e.resolution=+r("data-resolution")||500,e.toolName=r("data-tool")||null,e.userFromParams=r("data-user-from-params")||null,e.time=function(e){var t;if(e.timeStamp&&e.timeStamp>0){var n=Date.now()-e.timeStamp;if(n<0)t=function(){return e.timeStamp/1e3};else if(n>e.timeStamp){var o=performance.timing.navigationStart;t=function(e){return e+o}}else t=function(e){return e}}else t=function(){return Date.now()};return t}(document.createEvent("CustomEvent")),e.sessionID=r("data-session")||o,e.authHeader=r("data-auth")||null,e.custIndex=r("data-index")||null,e.sendProtocol="fetch"!==r("data-protocol")&&"XMLHttpRequest",e}()),w=Y,g=z,I=null,x=null,v=null,y=null,S=null,b=null,W=0,O=null,z.autostart&&function t(n){e.started||setTimeout((function(){var o=document.readyState;!n.autostart||"interactive"!==o&&"complete"!==o?t(n):(_(n),$(Y,n),e.started=n.on=!0,D({type:"load",logType:"raw",pageLoadTime:F-J},(function(){}),!1))}),100)}(z);e.buildPath=P,e.details=function(e,t){return{click:X,dblclick:X,mousedown:X,mouseup:X,focus:null,blur:null,input:e.logDetails?function(e){return{value:e.target.value}}:null,change:e.logDetails?function(e){return{value:e.target.value}}:null,dragstart:null,dragend:null,drag:null,drop:null,keydown:e.logDetails?function(e){return{key:e.keyCode,ctrl:e.ctrlKey,alt:e.altKey,shift:e.shiftKey,meta:e.metaKey}}:null,mouseover:null,wheel:function(e){return{x:e.deltaX,y:e.deltaY,z:e.deltaZ}},scroll:function(){return{x:window.scrollX,y:window.scrollY}},resize:function(){return{width:window.outerWidth,height:window.outerHeight}},submit:null}[t]},e.filter=function(e){I=e},e.getSelector=B,e.log=function(e){return null!==e&&"object"===t(e)&&(Y.push(e),!0)},e.map=function(e){x=e},e.options=function(e){return void 0!==e&&r(z,e),z},e.packageCustomLog=D,e.packageLog=M,e.start=function(){e.started&&!1!==z.autostart||(e.started=z.on=!0,z.autostart=!0)},e.stop=function(){e.started=z.on=!1,z.autostart=!1},e.version="2.3.0",Object.defineProperty(e,"__esModule",{value:!0})}));