/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@elastic/behavioral-analytics-browser-tracker@2.1.4/dist/iife/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var elasticAnalyticsDefault=(()=>{var d=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var A=(e,r)=>{for(var t in r)d(e,t,{get:r[t],enumerable:!0})},U=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of I(r))!P.call(e,s)&&s!==t&&d(e,s,{get:()=>r[s],enumerable:!(i=_(r,s))||i.enumerable});return e};var x=e=>U(d({},"__esModule",{value:!0}),e);var M={};A(M,{default:()=>V});var y=(e,r)=>{let t=document.referrer||"";return e==="page_view"?{...r,page:{...r.page||{},referrer:t,url:window.location.href,title:document.title}}:r},L={pageAttributes:y};function o(e){var r;let i=("; "+document.cookie).split("; "+e+"=");if(i.length===2&&i[1])return(r=i.pop())==null?void 0:r.split(";").shift()}function h(e,r,t,i="/"){var s="expires="+t.toUTCString();document.cookie=e+"="+r+"; "+s+"; path="+i}function w(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,function(e){return(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)})}var N=1,D=24*60*60*1e3,f=30*60*1e3,O=f,c="EA_UID",S="EA_SID",u="EA_SESSION_SAMPLED",C=class{constructor(e){this.userToken=e.user.token||o(c)||w(),this.userTokenExpirationInterval=e.user.lifetime||D,this.sessionTokenExpirationInterval=e.session.lifetime||f,this.sampling=e.sampling===void 0?N:e.sampling,o(u)?!this.isSessionSampled()&&this.sampling===1&&this.setSessionSampledExpire("true"):this.updateSessionSampledExpire(),this.userToken!==o(c)&&this.updateUserExpire()}getUserUuid(){let e=o(c);return e||(this.updateUserExpire(),e=o(c)),e}isSessionSampled(){return o(u)=="true"}updateSessionSampledExpire(){let e=o(u)||(Math.random()<=this.sampling).toString();this.setSessionSampledExpire(e)}setSessionSampledExpire(e){let r=new Date;r.setMilliseconds(O),h(u,e,r)}getSessionUuid(){return o(S)}updateSessionExpire(){let e=o(S)||w(),r=new Date;r.setMilliseconds(this.sessionTokenExpirationInterval),h(S,e,r)}updateUserExpire(){let e=new Date;e.setMilliseconds(this.userTokenExpirationInterval),h(c,this.userToken,e)}},R=(e,r,t)=>Object.values(t).reduce((i,s)=>s(e,i),{...r}),m=class{constructor(e){var r,t,i,s;if(!e.endpoint||!e.collectionName||!e.apiKey)throw new Error("Missing one or more of required options: endpoint, collectionName, apiKey");this.apiURL=`${e.endpoint}/_application/analytics/${e.collectionName}/event`,this.apiKey=e.apiKey,this.debug=e.debug||!1,this.userSessionStore=new C({user:{token:typeof((r=e.user)==null?void 0:r.token)=="function"?e.user.token():(t=e.user)==null?void 0:t.token,lifetime:(i=e.user)==null?void 0:i.lifetime},session:{lifetime:(s=e.session)==null?void 0:s.lifetime},sampling:e.sampling}),this.dataProviders={...L,...e.dataProviders||{}}}trackEvent(e,r){if(this.userSessionStore.updateSessionExpire(),this.userSessionStore.updateSessionSampledExpire(),!this.userSessionStore.isSessionSampled())return;let t=this.getUserSession(),i=R(e,{...r,...t},this.dataProviders),s=JSON.stringify(i);fetch(this.getEventTrackerURL(e),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Apikey ${this.apiKey}`},body:s}).then(a=>{if(!a.ok)return a.json()}).then(a=>{var E,v,k;let g=((v=(E=a==null?void 0:a.error)==null?void 0:E.caused_by)==null?void 0:v.reason)||((k=a==null?void 0:a.error)==null?void 0:k.reason);if(g)throw new Error(g)}).catch(a=>{a.name="TrackEventError",console.error(a)})}trackPageView(e){this.trackEvent("page_view",e||{})}trackSearchClick(e){this.trackEvent("search_click",e)}trackSearch(e){this.trackEvent("search",e)}getUserSession(){return{user:{id:this.userSessionStore.getUserUuid()},session:{id:this.userSessionStore.getSessionUuid()}}}getEventTrackerURL(e){let r=this.debug?"?debug=true":"";return`${this.apiURL}/${e}${r}`}};var n,p=[],T={createTracker:e=>(n=new m(e),p.forEach(([r,t])=>{n==null||n.trackEvent(r,t)}),n),trackPageView:e=>{if(!n){p.push(["page_view",{}]);return}n.trackPageView(e)},trackSearchClick:e=>{if(!n){p.push(["search_click",e]);return}n.trackSearchClick(e)},trackSearch:e=>{if(!n){p.push(["search",e]);return}n.trackSearch(e)}},l=()=>{T.trackPageView({})};window.addEventListener("pageshow",l);if(window.history){let e=window.history.pushState;window.history.pushState=(...r)=>(window.dispatchEvent(new Event("ewt:pushstate")),e.apply(window.history,r)),window.addEventListener("ewt:pushstate",l),window.addEventListener("popstate",l)}else window.addEventListener("hashchange",l);var V=T;return x(M);})();
var elasticAnalytics = elasticAnalyticsDefault.default
