blob: c8c399a291bf82efee20d5cb5a948147202df27b [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
*/
var userale=function(n){"use strict";var a,i,u,l,s,c,d,f,t="2.0.0";function e(n,o){Object.keys(o).forEach(function(t){if("userFromParams"===t){var e=function(t){var e=new RegExp("[?&]"+t+"(=([^&#]*)|&|#|$)"),n=window.location.href.match(e);return n&&n[2]?decodeURIComponent(n[2].replace(/\+/g," ")):null}(o[t]);e&&(n.userId=e)}n[t]=o[t]})}var o,r,m,p=null,g=null;function v(t,e){if(!i.on)return!1;var n=null;e&&(n=e(t));var o=function(t){return{milli:Math.floor(t),micro:Number((t%1).toFixed(3))}}(t.timeStamp&&0<t.timeStamp?i.time(t.timeStamp):Date.now()),r={target:h(t.target),path:w(t),pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,clientTime:o.milli,microTime:o.micro,location:function(t){return null!=t.pageX?{x:t.pageX,y:t.pageY}:null!=t.clientX?{x:document.documentElement.scrollLeft+t.clientX,y:document.documentElement.scrollTop+t.clientY}:{x:null,y:null}}(t),type:t.type,logType:"raw",userAction:!0,details:n,userId:i.userId,toolVersion:i.version,toolName:i.toolName,useraleVersion:i.useraleVersion,sessionID:i.sessionID};return!("function"==typeof p&&!p(r))&&("function"==typeof g&&(r=g(r)),a.push(r),!0)}function h(t){return t.localName?t.localName+(t.id?"#"+t.id:"")+(t.className?"."+t.className:""):t.nodeName?t.nodeName+(t.id?"#"+t.id:"")+(t.className?"."+t.className:""):t&&t.document&&t.location&&t.alert&&t.setInterval?"Window":"Unknown"}function w(t){var e=[];if(t.path)e=t.path;else for(var n=t.target;n;)e.push(n),n=n.parentElement;return function(t){var e,n=0,o=[];for(;e=t[n];)o.push(h(e)),++n;return o}(e)}var y=["click","focus","blur","input","change","mouseover","submit"],S=["load","blur","focus"];function E(t){return{clicks:t.detail,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey,meta:t.metaKey}}function I(n){return function(t){o={click:E,dblclick:E,mousedown:E,mouseup:E,focus:null,blur:null,input:t.logDetails?function(t){return{value:t.target.value}}:null,change:t.logDetails?function(t){return{value:t.target.value}}:null,dragstart:null,dragend:null,drag:null,drop:null,keydown:t.logDetails?function(t){return{key:t.keyCode,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey,meta:t.metaKey}}:null,mouseover:null,submit:null},r={},m={wheel:function(t){return{x:t.deltaX,y:t.deltaY,z:t.deltaZ}},scroll:function(){return{x:window.scrollX,y:window.scrollY}},resize:function(){return{width:window.outerWidth,height:window.outerHeight}}}}(n),Object.keys(o).forEach(function(e){document.addEventListener(e,function(t){v(t,o[e])},!0)}),y.forEach(function(t){document.addEventListener(t,function(t){!function(t){var e=h(t.target),n=w(t),o=t.type,r=Math.floor(t.timeStamp&&0<t.timeStamp?i.time(t.timeStamp):Date.now());if(null==u&&(u=e,l=o,s=n,c=r,d=0),u!==e||l!==o){if(f={target:u,path:s,pageUrl:window.location.href,pageTitle:document.title,pageReferrer:document.referrer,count:d,duration:r-c,startTime:c,endTime:r,type:l,logType:"interval",targetChange:u!==e,typeChange:l!==o,userAction:!1,userId:i.userId,toolVersion:i.version,toolName:i.toolName,useraleVersion:i.useraleVersion,sessionID:i.sessionID},"function"==typeof p&&!p(f))return;"function"==typeof g&&(f=g(f)),a.push(f),u=e,l=o,s=n,c=r,d=0}u==e&&l==o&&(d+=1)}(t)},!0)}),Object.keys(m).forEach(function(e){r[e]=!0,window.addEventListener(e,function(t){r[e]&&(r[e]=!1,v(t,m[e]),setTimeout(function(){r[e]=!0},n.resolution))},!0)}),S.forEach(function(t){window.addEventListener(t,function(t){v(t,function(){return{window:!0}})},!0)}),!0}var N=null;function T(t,e){null!==N&&clearInterval(N),N=function(t,e){return setInterval(function(){e.on&&t.length>=e.logCountThreshold&&(b(t.slice(0),e.url,0),t.splice(0))},e.transmitInterval)}(t,e),function(t,e){if(!e.on)return;navigator.sendBeacon?window.addEventListener("unload",function(){navigator.sendBeacon(e.url,JSON.stringify(t))}):window.addEventListener("beforeunload",function(){0<t.length&&b(t,e.url,1)})}(t,e)}function b(t,e,n){var o=new XMLHttpRequest,r=JSON.stringify(t);o.open("POST",e),o.setRequestHeader("Content-type","application/json;charset=UTF-8"),o.onreadystatechange=function(){4===o.readyState&&200!==o.status&&0<n&&b(t,e,n--)},o.send(r)}var D,k,C,K,L={},x=[];function V(e){n.started||setTimeout(function(){var t=document.readyState;"interactive"===t||"complete"===t?(I(e),T(x,e),n.started=e.on=!0):V(e)},100)}n.started=!1,L.on=!1,L.useraleVersion=t,e(L,(k={},C=document.currentScript||(D=document.getElementsByTagName("script"))[D.length-1],K=C?C.getAttribute.bind(C):function(){return null},k.autostart="false"!==K("data-autostart"),k.url=K("data-url")||"http://localhost:8000",k.transmitInterval=+K("data-interval")||5e3,k.logCountThreshold=+K("data-threshold")||5,k.userId=K("data-user")||null,k.version=K("data-version")||null,k.logDetails="true"===K("data-log-details"),k.resolution=+K("data-resolution")||500,k.toolName=K("data-tool")||null,k.userFromParams=K("data-user-from-params")||null,k.time=function(t){if(t.timeStamp&&0<t.timeStamp){var e,n=Date.now()-t.timeStamp;if(n<0)e=function(){return t.timeStamp/1e3};else if(n>t.timeStamp){var o=performance.timing.navigationStart;e=function(t){return t+o}}else e=function(t){return t}}else e=function(){return Date.now()};return e}(document.createEvent("CustomEvent")),k.sessionID=K("data-session")||"session_"+String(Date.now()),k)),a=x,i=L,d=0,f=c=s=l=u=g=p=null,L.autostart&&V(L);return n.filter=function(t){p=t},n.log=function(t){return null!==t&&"object"==typeof t&&(x.push(t),!0)},n.map=function(t){g=t},n.options=function(t){return void 0!==t&&e(L,t),L},n.start=function(){n.started||V(L),L.on=!0},n.stop=function(){L.on=!1},n.version="2.0.0",n}({});