blob: c84afd82c73accf04b09fbca21334e766e51fc7c [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.4.0",r=null,o=null;function i(e,t){return null===window.sessionStorage.getItem(e)?(window.sessionStorage.setItem(e,JSON.stringify(t)),t):JSON.parse(window.sessionStorage.getItem(e))}function a(e,t){var n=e.autostart,r=t.autostart;Object.keys(t).forEach((function(n){if("userFromParams"===n){var r=(o=t[n],i=new RegExp("[?&]"+o+"(=([^&#]*)|&|#|$)"),(a=window.location.href.match(i))&&a[2]?decodeURIComponent(a[2].replace(/\+/g," ")):null);r&&(e.userId=r)}var o,i,a;e[n]=t[n]})),!1!==n&&!1!==r||(e.autostart=!1)}var s=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))},l=function(e,t,n){this.name=e,this.version=t,this.os=n,this.type="browser"},u=function(e){this.version=e,this.type="node",this.name="node",this.os=process.platform},c=function(e,t,n,r){this.name=e,this.version=t,this.os=n,this.bot=r,this.type="bot-device"},d=function(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null},f=function(){this.type="react-native",this.name="react-native",this.version=null,this.os=null},m=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,p=3,h=[["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/]],w=[["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 g(e){var t=function(e){return""!==e&&h.reduce((function(t,n){var r=n[0],o=n[1];if(t)return t;var i=o.exec(e);return!!i&&[r,i]}),!1)}(e);if(!t)return null;var n=t[0],r=t[1];if("searchbot"===n)return new d;var o=r[1]&&r[1].split(".").join("_").split("_").slice(0,3);o?o.length<p&&(o=s(s([],o,!0),function(e){for(var t=[],n=0;n<e;n++)t.push("0");return t}(p-o.length),!0)):o=[];var i=o.join("."),a=function(e){for(var t=0,n=w.length;t<n;t++){var r=w[t],o=r[0];if(r[1].exec(e))return o}return null}(e),u=m.exec(e);return u&&u[1]?new c(n,i,a,u[1]):new l(n,i,a)}var v,y,b,S,O,I,k,E,W,T,N,A,x=v?g(v):"undefined"==typeof document&&"undefined"!=typeof navigator&&"ReactNative"===navigator.product?new f:"undefined"!=typeof navigator?g(navigator.userAgent):"undefined"!=typeof process&&process.version?new u(process.version.slice(1)):null,j={};function C(e,t){if(!b.on)return!1;var n=null;t&&(n=t(e));for(var r,o=(r=e.timeStamp&&e.timeStamp>0?b.time(e.timeStamp):Date.now(),{milli:Math.floor(r),micro:Number((r%1).toFixed(3))}),i={target:P(e.target),path:K(e),pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,browser:V(),clientTime:o.milli,microTime:o.micro,location:M(e),scrnRes:B(),type:e.type,logType:"raw",userAction:!0,details:n,userId:b.userId,toolVersion:b.version,toolName:b.toolName,useraleVersion:b.useraleVersion,sessionID:b.sessionID,httpSessionId:b.httpSessionId,browserSessionId:b.browserSessionId},a=0,s=Object.values(j);a<s.length;a++){var l=s[a];if("function"==typeof l&&!(i=l(i,e)))return!1}return y.push(i),!0}function D(e,t,n){if(!b.on)return!1;var r=null;t&&(r=t());for(var o={pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,browser:V(),clientTime:Date.now(),scrnRes:B(),logType:"custom",userAction:n,details:r,userId:b.userId,toolVersion:b.version,toolName:b.toolName,useraleVersion:b.useraleVersion,sessionID:b.sessionID,httpSessionId:b.httpSessionId,browserSessionId:b.browserSessionId},i=Object.assign(o,e),a=0,s=Object.values(j);a<s.length;a++){var l=s[a];if("function"==typeof l&&!(i=l(i,null)))return!1}return y.push(i),!0}function M(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 B(){return{width:window.innerWidth,height:window.innerHeight}}function P(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 K(e){if(e instanceof window.Event)return function(e){var t,n=0,r=[];for(;t=e[n];)r.push(P(t)),++n;return r}(e.composedPath())}function V(){return{browser:x?x.name:"",version:x?x.version:""}}var R,L=["click","focus","blur","input","change","mouseover","submit"],$=["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},N={},A={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}}},R={submit:null}}(e),Object.keys(T).forEach((function(e){document.addEventListener(e,(function(t){C(t,T[e])}),!0)})),L.forEach((function(e){document.addEventListener(e,(function(e){!function(e){var t=P(e.target),n=K(e),r=e.type,o=Math.floor(e.timeStamp&&e.timeStamp>0?b.time(e.timeStamp):Date.now());if(null==S&&(S=t,O=r,I=n,k=o,E=0),S!==t||O!==r){W={target:S,path:I,pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,browser:V(),count:E,duration:o-k,startTime:k,endTime:o,type:O,logType:"interval",targetChange:S!==t,typeChange:O!==r,userAction:!1,userId:b.userId,toolVersion:b.version,toolName:b.toolName,useraleVersion:b.useraleVersion,sessionID:b.sessionID,httpSessionId:b.httpSessionId,browserSessionId:b.browserSessionId};for(var i=0,a=Object.values(j);i<a.length;i++){var s=a[i];if("function"==typeof s&&!(W=s(W,null)))return!1}y.push(W),S=t,O=r,I=n,k=o,E=0}S==t&&O==r&&(E+=1)}(e)}),!0)})),Object.keys(A).forEach((function(t){N[t]=!0,window.addEventListener(t,(function(n){N[t]&&(N[t]=!1,C(n,A[t]),setTimeout((function(){N[t]=!0}),e.resolution))}),!0)})),Object.keys(R).forEach((function(e){document.addEventListener(e,(function(t){C(t,T[e])}),!0)})),$.forEach((function(e){window.addEventListener(e,(function(e){C(e,(function(){return{window:!0}}))}),!0)})),!0}function H(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function U(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,s=[],l=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(e){u=!0,o=e}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw o}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return H(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?H(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var z=null;var F=null;function Y(e,t){null!==F&&clearInterval(F),F=function(e,t){return setInterval((function(){t.on&&e.length>=t.logCountThreshold&&(J(e.slice(0),t,0),e.splice(0))}),t.transmitInterval)}(e,t),function(e,t){window.addEventListener("pagehide",(function(){t.on&&e.length>0&&(navigator.sendBeacon(t.url,JSON.stringify(e)),e.splice(0))}))}(e,t)}function J(e,t,n){var r=new XMLHttpRequest,o=JSON.stringify(e);r.open("POST",t.url),function(e){if(z)try{e.authHeader=z()}catch(e){console.error("Error encountered while setting the auth header: ".concat(e))}}(t),t.authHeader&&r.setRequestHeader("Authorization",t.authHeader),r.setRequestHeader("Content-type","application/json;charset=UTF-8"),t.headers&&Object.entries(t.headers).forEach((function(e){var t=U(e,2),n=t[0],o=t[1];r.setRequestHeader(n,o)})),r.onreadystatechange=function(){4===r.readyState&&200!==r.status&&n>0&&J(e,t,n--)},r.send(o)}var q,G={},Q=[],Z=Date.now();window.onload=function(){q=Date.now()},e.started=!1,G.on=!1,G.useraleVersion=n,a(G,function(){var e,t={};null===r&&(r=i("userAleSessionId","session_"+String(Date.now()))),null===o&&(o=i("userAleHttpSessionId",(e=new Uint8Array(16),window.crypto.getRandomValues(e),Array.from(e,(function(e){return e.toString(16).padStart(2,"0")})).join(""))));var n,a=document.currentScript||(n=document.getElementsByTagName("script"))[n.length-1],s=a?a.getAttribute.bind(a):function(){return null};return t.autostart="false"!==s("data-autostart"),t.url=s("data-url")||"http://localhost:8000",t.transmitInterval=+s("data-interval")||5e3,t.logCountThreshold=+s("data-threshold")||5,t.userId=s("data-user")||null,t.version=s("data-version")||null,t.logDetails="true"===s("data-log-details"),t.resolution=+s("data-resolution")||500,t.toolName=s("data-tool")||null,t.userFromParams=s("data-user-from-params")||null,t.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 r=performance.timing.navigationStart;t=function(e){return e+r}}else t=function(e){return e}}else t=function(){return Date.now()};return t}(document.createEvent("CustomEvent")),t.sessionID=s("data-session")||r,t.httpSessionId=o,t.browserSessionId=null,t.authHeader=s("data-auth")||null,t.custIndex=s("data-index")||null,t.headers=s("data-headers")||null,t}()),y=Q,b=G,j=[],S=null,O=null,I=null,k=null,E=0,W=null,G.autostart&&function t(n){e.started||setTimeout((function(){var r=document.readyState;!n.autostart||"interactive"!==r&&"complete"!==r?t(n):(_(n),Y(Q,n),e.started=n.on=!0,D({type:"load",details:{pageLoadTime:q-Z}},(function(){}),!1))}),100)}(G);var ee=n;e.addCallbacks=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.forEach((function(e){var t=Object.keys(e).reduce((function(t,n){return t[n]=Object.getOwnPropertyDescriptor(e,n),t}),{});Object.getOwnPropertySymbols(e).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e,n);r.enumerable&&(t[n]=r)})),Object.defineProperties(j,t)})),j},e.buildPath=K,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.getSelector=P,e.log=function(e){return null!==e&&"object"===t(e)&&(Q.push(e),!0)},e.options=function(e){return void 0!==e&&a(G,e),G},e.packageCustomLog=D,e.packageLog=C,e.registerAuthCallback=function(e){try{return function(e){if("function"!=typeof e)throw new Error("Userale auth callback must be a function");var t=e();if("string"!=typeof t)throw new Error("Userale auth callback must return a string")}(e),z=e,!0}catch(e){return!1}},e.removeCallbacks=function(e){e.forEach((function(e){Object.hasOwn(j,e)&&delete j[e]}))},e.start=function(){e.started&&!1!==G.autostart||(e.started=G.on=!0,G.autostart=!0)},e.stop=function(){e.started=G.on=!1,G.autostart=!1},e.version=ee}));