(()=>{function e(){return window.unifiedSDK}function t(e=null){const n={},r=new Set;let i,a=!1;return Object.defineProperty(n,"__isObservable",{value:!0,writable:!1,enumerable:!1,configurable:!1}),n.subscribe=t=>{if("function"!=typeof t)throw new Error("Invalid Argument: subscribe needs to be called with a function");return r.add(t),a||(a=!0,"function"==typeof e&&(i=e(n.next))),()=>{if(r.delete(t),0===r.size)return n.dispose()}},n.next=e=>{r.forEach((t=>{t(e)}))},n.pipe=(...e)=>{if(0===e.length)throw new Error("No pipe callback provided");let r=n;return e.forEach((e=>{if("function"!=typeof e)throw new Error("Invalid Argument: pipe can only be called with functions");const n=r;r=t((t=>n.subscribe((n=>e(n,t)))))})),r},n.dispose=async()=>{r.clear(),a=!1,i instanceof Promise&&(i=await i),"function"==typeof i&&await i()},n}function n(...e){return t((t=>{const n=e.map((e=>e.subscribe(t)));return()=>{n.forEach((e=>e()))}}))}function r(e,n,...r){return t((t=>{const i=e=>{try{t(e)}catch(e){}};return n.forEach((t=>e.addEventListener(t,i,...r))),()=>{n.forEach((t=>e.removeEventListener(t,i)))}}))}function i(e){let t,n=[];return(r,i)=>{n.push(r),clearTimeout(t),t=setTimeout((()=>{i(n),n=[]}),e)}}function a(e){return new Proxy(e,{set:()=>!0,get:(e,t)=>{const n=e[t];return"object"==typeof n&&null!==n?a(n):n}})}function o(e,t){return t.pipe((async(t,n)=>{if(e.state.initialized){const t=function(e){let t=0,n=0;return Object.values(e).filter((e=>e.enabled)).forEach((e=>{n+=e.weight;let r=e.events.length;if(r>0){let n=r;if(e.fadeTime&&"number"==typeof e.fadeTime&&e.fadeTime>0){r=0,n=0;const t=Date.now();e.events.forEach((i=>{const a=t-i.timestamp;a<=e.fadeTime&&(r++,n+=1-a/e.fadeTime)}))}if(1==e.minThreshold&&1==e.maxThreshold)t+=1/e.weight;else if(n>=e.maxThreshold)t+=Math.min(1,n/e.maxThreshold);else if(r>=e.minThreshold){const r=e.minThreshold-e.minThreshold/e.maxThreshold,i=n-r,a=e.maxThreshold-e.minThreshold,o=Math.max(0,i/a),s=Math.min(1,o*e.weight);t+=s}}})),n?t/n:0}(e.state.indicators);t!=e.getScore()&&n({type:"liveScore",data:{group:e.state.groupName,score:t}})}}))}function s(t,r){const i={},s={groupName:t,enabled:r.enabled,initialized:!1,indicators:r.indicators,severityLevel:r.severityLevel,score:0};let c=null;i.state=a(s);const l=function(t){const n={},r={groupName:t,pageChangePersistence:!1,initialized:!1,indicators:{}};n.state=a(r);let i,o,s=null,c=null;return n.initialize=async t=>{({loader:i,logger:o}=e()),r.pageChangePersistence=t,t&&([c]=await i.requireModules(["database"])),r.initialized=!0},n.checkDatabaseConnection=async()=>{if(!c)return!1;let e=!1;try{await c.openDatabase("scoringState"),e=!0}catch(e){o.warn("Connecting to indexed database failed, indicators for live scoring can not be persisted",e),c=null}return e},n.persistIndicators=async e=>{r.indicators={...e},s=setTimeout(n.persistIndicatorsWithTimeout,500)},n.persistIndicatorsWithTimeout=async()=>{if(r.pageChangePersistence&&await n.checkDatabaseConnection()){const e=c.getObjectStore("scoring");Object.entries(r.indicators).forEach((([t,n])=>{n.enabled&&n.pageChangePersistent&&e.put({indicator:t,events:n.events.filter((e=>e.currentPI)).map((e=>({timestamp:e.timestamp,currentPI:e.currentPI})))})}))}clearTimeout(s),s=null},n.restorePersistedIndicators=async e=>{if(r.pageChangePersistence&&await n.checkDatabaseConnection()){const t=c.getObjectStore("scoring"),n=async([e,n])=>{if(n.pageChangePersistent){const r=await t.get(e);r&&r.hasOwnProperty("events")&&r.events.length&&(n.events=r.events.map((e=>(e.currentPI=!1,e))))}};Object.entries(e).forEach(n)}return e},n.waitForPersistenceTimeout=async()=>{s&&await n.persistIndicatorsWithTimeout()},n}(t);let u=!1;return i.initialize=async(e,t,r)=>{Object.entries(e).forEach((([e,t])=>{s.indicators[e]={events:[],...s.indicators[e],...t},t.pageChangePersistent&&(u=!0)})),c=o(i,n(t,r.pipe((async(e,t)=>{await i.pageChangeReset(),t(e)})),i.getIndicatorObservables().pipe((e=>{i.updateIndicator(e.type,e.timestamp)})))).pipe(((e,t)=>{i.updateScore(e.data.score),t(e)})),await l.initialize(u,s.indicators),u&&(s.indicators=await l.restorePersistedIndicators(s.indicators)),s.initialized=!0},i.getObservable=()=>c,i.getIndicatorObservables=()=>n(...Object.values(s.indicators).filter((e=>e.enabled)).map((e=>e.observable))),i.getScore=()=>s.score,i.updateScore=e=>{s.score=e},i.updateIndicator=(e,t)=>{const n=s.indicators.hasOwnProperty(e)?s.indicators[e]:null;if(n){if(n.events.push({timestamp:+t,currentPI:!0}),n.fadeTime&&"number"==typeof n.fadeTime&&n.fadeTime>0){const e=Date.now();n.events=n.events.filter((t=>e-t.timestamp<=n.fadeTime))}else n.maxThreshold&&n.events.length>n.maxThreshold&&(n.events=n.events.slice(-1*n.maxThreshold));l.persistIndicators(s.indicators)}},i.pageChangeReset=async()=>{await l.waitForPersistenceTimeout(),Object.values(s.indicators).forEach((e=>{e.events=[]})),s.indicators=await l.restorePersistedIndicators(s.indicators),l.persistIndicators(s.indicators)},i.getSeverityLevel=()=>{let e="none",t=0;return s.score>0&&Object.entries(s.severityLevel).forEach((([n,r])=>{s.score>=r&&r>t&&(t=r,e=n)})),e},i.getSeverityLevelRange=e=>{if(!e||!e.min&&!e.max)return!1;const t=!e.min||s.score>=s.severityLevel[e.min],n=!e.max||s.score{const{pageX:r,pageY:i,timeStamp:a}=e,o={timeStamp:a,pageX:r,pageY:i},s=t.lastClickEvents[t.lastClickEvents.length-1]||null;if(s){const e=function(e,t,n,r,i){const a=Math.abs(e-n),o=Math.abs(t-r);return Math.max(a,o)<=i}(r,i,s.pageX,s.pageY,t.clickRadius);(o.timeStamp-s.timeStamp>t.timeWindow||!e)&&(t.lastClickEvents=[])}t.lastClickEvents.push(o),t.lastClickEvents.length===t.clickThreshold&&n({type:"rageClick",data:{clickCount:t.lastClickEvents.length},timestamp:Date.now()})}))}function l(e){let a=null,o=null;const s=r(document,["mousedown","touchstart"]).pipe((()=>{a=Date.now(),o=null})),c=n(r(document,["blur"]),r(document,["focus"],!0),function(e,n){return t((t=>{const r=new MutationObserver((e=>{e.forEach((e=>t({type:"mutation",mutation:e})))}));return r.observe(e,n),()=>r.disconnect()}))}(document,{childList:!0,attributes:!0,characterData:!0,subtree:!0})).pipe((()=>{o=Date.now()}));return n(s,c,r(document,["click"]).pipe(i(e.timeWindow))).pipe(((t,n)=>{if(null!==a&&null!==o){if(o-a{const n=e.timeThreshold,r=function(){let e=0;if(performance&&"function"==typeof performance.getEntriesByType&&performance.getEntriesByType("navigation").length){const[t]=performance.getEntriesByType("navigation");e=Math.round(t.domComplete)}else performance&&"object"==typeof performance.timing&&(e=Math.round(performance.timing.domComplete-performance.timing.navigationStart));return e}();r>=n&&setTimeout((()=>{t({type:"pageRenderingTime",data:{domLoadTime:r},timestamp:Date.now()})}),10)}))}function d(){return r(window,["error"]).pipe(((e,t)=>{const{message:n,lineno:r,colno:i,filename:a}=e,o=`${r}:${i}`;(function(e){const t=/^https?:\/\/(localhost(:\d{1,5})?|([^/]+).verint-(cdn|api).com)\//;return Boolean(e.match(t))})(a)||t({type:"javaScriptErrors",data:{type:"error",message:n,line:o,scriptUrl:a},timestamp:Date.now()})}))}function p(t){const{loader:n}=e();return n.getModuleSync("visitor").getPageChangeObservable().pipe(((e,n)=>{(function(e,t){if("string"!=typeof e)return!1;if(!Array.isArray(t))return!1;const n=t.find((t=>Boolean(e.match(new RegExp(t,"i")))));return Boolean(n)})(e.pagename,t.pagenames)&&setTimeout((()=>{n({type:"errorPage",data:{pagename:e.pagename},timestamp:Date.now()})}),10)}))}function g(n){const{loader:r}=e(),i=r.getModuleSync("visitor"),a=i.getPropertyObservable();return t((e=>(i.getProperties().forEach((t=>{m(t,n.properties)&&setTimeout((()=>{e({type:"errorMessage",data:{propertyName:t.name,propertyValue:t.value},timestamp:Date.now()})}),10)})),a.subscribe((t=>{m(t,n.properties)&&setTimeout((()=>{e({type:"errorMessage",data:{propertyName:t.name,propertyValue:t.value},timestamp:Date.now()})}),10)})))))}function m(e,t){if(!e?.name)return!1;if(!Array.isArray(t))return!1;let n=e.value;null==n&&(n="");const r=t.find((t=>"string"==typeof t?.name&&"string"==typeof t?.value&&Boolean(e.name.match(new RegExp(t.name,"i"))&&n.match(new RegExp(t.value,"i")))));return Boolean(r)}function f(){return document.scrollingElement||document.body.parentNode||document.body||document.documentElement}function h(){const e=f().scrollHeight-window.innerHeight;return Math.max(0,Math.min(f().scrollTop,e))}function b(e){const t=e.directionThreshold,n=e.minScrollLength;return function(){let e=null,t=null,n=null,i=0;return r(document,["scroll"]).pipe(((r,a)=>{const o=h();if(null===t)return void(t=o);const s=function(e,t){if(e>t)return"up";if(e{const i=e.filter((e=>e.distance>=n));i.length>=t&&r({type:"highScrollActivity",data:{value:i.length},timestamp:Date.now()})}))}function v(e,t){return!(!e||"object"!=typeof e||"string"!=typeof e.tagName)&&(Array.isArray(t)?t.some((t=>v(e,t))):"string"==typeof t&&e.tagName.toUpperCase()===t.toUpperCase())}function y(e,t){return!(!e||"object"!=typeof e||!e.hasAttribute)&&e.hasAttribute(t)}function w(e){return!!v(e,["textarea","option","select"])||(!(!v(e,"input")||["button","submit","reset"].includes(e.type))||!!y(e,"contenteditable"))}function E(e){let t=null;return n(r(document,["focus"],!0).pipe((e=>{t=!w(e.target)||["button","radio","checkbox","color","file","image","range","reset","submit"].includes(e.target.type)?null:e.target})),r(document,["keyup"]).pipe(i(e.timeWindow))).pipe(((e,n)=>{Array.isArray(e)&&e[0].target==t?n({type:"longInputTime",data:{},timestamp:Date.now()}):t=null}))}function T(t){const{loader:a}=e(),o=a.getModuleSync("visitor").getPageChangeObservable();let s=[];return n(r(document,["focus"],!0).pipe((e=>{var t;!e.target||!w(e.target)||v(t=e.target,"input")&&"password"===t.type||(s.find((({element:t})=>t===e.target))||s.push({element:e.target,count:0}))})),o,r(document,["change"],!0),r(document,["input"],!0).pipe(i(t.inputDebounce))).pipe(((e,n)=>{if("pageChange"===e.type)return void(s=[]);if(Array.isArray(e)&&!y((e=e[0]).target,"contenteditable"))return;const r=s.find((({element:t})=>t===e.target));r&&(r.count++,r.count>=t.changeThreshold&&n({type:"formCorrection",data:{},timestamp:Date.now()}))}))}const{loader:C,config:I}=e();C.resolveModule("scoringEngine",(async()=>{const[r]=await C.requireModules(["visitor"]),i=r.getPageChangeObservable();var o;const m=function({heartbeatObservable:r,pageChangeObservable:i}){const{events:o,config:c}=e(),l={},u={groups:{},indicators:{},indicatorRegisterFNs:{},indicatorPageChangeInitialized:!1};return l.state=a(u),l.start=()=>{const e=c.getConfig("scoringEngine.indicators");Object.entries(e).forEach((([e,t])=>{l.prepareIndicator(e,t)}));const t=c.getConfig("scoringEngine.groups");Object.entries(t).forEach((([e,t])=>{l.prepareGroup(e,t)})),o.triggerEvent("scoringEngine:ready",{scoringEngine:l})},l.stop=()=>{r.dispose(),i.dispose(),Object.values(u.indicators).forEach((e=>{e.enabled&&e.observable.dispose()})),Object.values(u.groups).forEach((e=>{e.state.enabled&&e.getObservable().dispose()}))},l.getState=()=>u,l.getHeartbeatObservable=()=>r,l.getPageChangeObservable=()=>i,l.prepareGroup=(e,t)=>{u.groups[e]=s(e,t);const n=u.groups[e];if(n.state.enabled){const e={};Object.entries(n.state.indicators).forEach((([t,n])=>{n.enabled&&(l.enableIndicator(t),e[t]={...n,...u.indicators[t]})})),n.initialize(e,r,i)}},l.registerIndicator=(e,t)=>{u.indicatorRegisterFNs[e]=t},l.prepareIndicator=(e,t)=>{"function"==typeof u.indicatorRegisterFNs[e]&&(u.indicators[e]={enabled:!1,events:[],...t})},l.enableIndicator=e=>{u.indicators[e].enabled=!0,u.indicators[e].observable=u.indicatorRegisterFNs[e](u.indicators[e]).pipe(((t,n)=>{t.timestamp=t.timestamp||Date.now(),u.indicators[e].events.push(t),n(t)})),u.indicators[e].getObservable=()=>n(u.indicators[e].observable,l.replayObservable(e))},l.getGroup=e=>u.groups[e]||null,l.getRunningGroups=()=>{const e={};return Object.entries(u.groups).forEach((([t,n])=>{n.state.enabled&&(e[t]=n)})),e},l.getIndicator=e=>{const t=u.indicators[e];return t.enabled||l.enableIndicator(e),t},l.getRunningIndicators=()=>{const e={};return Object.entries(u.indicators).forEach((([t,n])=>{n.enabled&&(e[t]=n)})),e},l.getRunningIndicatorsObservable=()=>n(...Object.values(l.getRunningIndicators()).map((e=>e.getObservable()))),l.indicatorPersistenceCleanup=()=>{u.indicatorPageChangeInitialized||(u.indicatorPageChangeInitialized=!0,i.subscribe((()=>{Object.values(u.indicators).forEach((e=>{e.events=[]}))})))},l.replayObservable=e=>{l.indicatorPersistenceCleanup();const n=t((t=>{u.indicators[e].events.forEach((n=>{t({type:e,timestamp:n.timestamp,data:n.data})})),n.dispose()}));return n},l}({heartbeatObservable:(o=I.getConfig("scoringEngine.heartbeat"),t((e=>{const t=setInterval((()=>e({type:"heartbeat"})),o);return()=>{clearInterval(t)}}))),pageChangeObservable:i});return m.registerIndicator("rageClick",c),m.registerIndicator("deadClick",l),m.registerIndicator("pageRenderingTime",u),m.registerIndicator("javaScriptErrors",d),m.registerIndicator("errorPage",p),m.registerIndicator("errorMessage",g),m.registerIndicator("highScrollActivity",b),m.registerIndicator("longInputTime",E),m.registerIndicator("formCorrection",T),m}))})();