(()=>{function $(t){let i=document.querySelector(t);if(!i)throw`Pirsch script ${t} tag not found!`;return i}function c(t,i){let e="";return t.length>0&&(i{r=r.trim().replaceAll("-"," "),r&&(i[r]="1")});return i}function M(t){return window.localStorage!==void 0&&window.localStorage.getItem("disable_pirsch")||st(t)||!ct(t)||dt(t)}function R(t){return t?t=location.href.replace(location.hostname,t):t=location.href,t}function C(t,i,e){t||(t=location.href),i||(i=""),e||(e="");let r=new URL(t);return r.pathname=i+r.pathname+e,r.toString()}function N(t,i){let e=document.title;return t||(t=""),i||(i=""),t+e+i}function I(t){let i=document.referrer;return t&&(i=i.replace(location.hostname,t)),i}function q(t){try{let i=new URL(t);return i.search="",i.toString()}catch{return t}}function U(t){try{let i=new URL(t);return i.hash="",i.toString()}catch{return t}}function st(t){return!t.hasAttribute("data-dev")&&(/^localhost(.*)$|^127(\.[0-9]{1,3}){3}$/is.test(location.hostname)||location.protocol==="file:")?(console.info("Pirsch is ignored on localhost. Add the data-dev attribute to enable it."),!0):!1}function ct(t){try{let i=t.getAttribute("data-include"),e=i?i.split(","):[];if(e.length){let r=!1;for(let o=0;oQ(t))}document.body?Q(t):window.addEventListener("DOMContentLoaded",()=>Q(t))}function Q(t){let{script:i,domains:e,rewrite:r,pathPrefix:o,pathSuffix:f,titlePrefix:l,titleSuffix:h,identificationCode:d,endpoint:m,disableQueryParams:g,disableReferrer:x,disableResolution:A,stripAnchor:S}=t;j({script:i,hostname:r,pathPrefix:e.length?"":c(o,0),pathSuffix:e.length?"":c(f,0),titlePrefix:e.length?"":c(l,0),titleSuffix:e.length?"":c(h,0),identificationCode:d,endpoint:m,disableQueryParams:g,disableReferrer:x,disableResolution:A,stripAnchor:S});for(let u=0;u`tag_${y.replaceAll("-"," ")}=${v||1}`).join("&"):""),w=new XMLHttpRequest;w.open("GET",b),w.send()}function B(){window.pirsch=function(t,i){return console.log(`Pirsch event: ${t}${i?" "+JSON.stringify(i):""}`),Promise.resolve(null)}}function J(t){let{script:i,domains:e,rewrite:r,pathPrefix:o,pathSuffix:f,titlePrefix:l,titleSuffix:h,identificationCode:d,endpoint:m,disableQueryParams:g,disableReferrer:x,disableResolution:A,stripAnchor:S}=t;window.pirsch=function(u,b){return typeof u!="string"||!u?Promise.reject("The event name for Pirsch is invalid (must be a non-empty string)! Usage: pirsch('event name', {duration: 42, meta: {key: 'value'}})"):new Promise((w,y)=>{let v=b&&b.meta?b.meta:{};for(let p in v)v.hasOwnProperty(p)&&(v[p]=String(v[p]));z({script:i,hostname:r,pathPrefix:e.length?"":c(o,0),pathSuffix:e.length?"":c(f,0),titlePrefix:e.length?"":c(l,0),titleSuffix:e.length?"":c(h,0),identificationCode:d,endpoint:m,disableQueryParams:g,disableReferrer:x,disableResolution:A,stripAnchor:S,name:u,options:b,meta:v,non_interactive:t.non_interactive,resolve:w,reject:y});for(let p=0;p{ut({domains:e,rewrite:r,pathPrefix:o,pathSuffix:f,identificationCode:l,endpoint:h,disableQueryParams:d})},m);window.pirschClearSession=()=>{clearInterval(g)}}function ut(t){let{domains:i,rewrite:e,pathPrefix:r,pathSuffix:o,identificationCode:f,endpoint:l,disableQueryParams:h}=t;X({hostname:e,pathPrefix:i.length?"":c(r,0),pathSuffix:i.length?"":c(o,0),identificationCode:f,endpoint:l,disableQueryParams:h});for(let d=0;d{D(P)}),P.addEventListener("auxclick",()=>{D(P)})}function D(a){let n=a.getAttribute("pirsch-event")??a.getAttribute("data-pirsch-event");if(!n){console.error("Pirsch event attribute name can not be empty!",a);return}let P={},E;for(let s of a.attributes)s.name.startsWith("data-pirsch-meta-")?P[s.name.substring(17)]=s.value:s.name.startsWith("pirsch-meta-")?P[s.name.substring(12)]=s.value:(s.name.startsWith("data-pirsch-duration")||s.name.startsWith("pirsch-duration"))&&(E=Number.parseInt(s.value,10)??0);pirsch(n,{meta:P,duration:E,non_interactive:a.hasAttribute("pirsch-non-interactive")||a.hasAttribute("data-pirsch-non-interactive")})}function Y(){let a=document.querySelectorAll("[class*='pirsch-event=']");for(let n of a)n.addEventListener("click",()=>{F(n)}),n.addEventListener("auxclick",()=>{F(n)})}function F(a){let n="",P={},E;for(let s of a.classList)if(s.startsWith("pirsch-event=")){if(n=s.substring(13).replaceAll("+"," "),!n){console.error("Pirsch event class name can not be empty!",a);return}}else if(s.startsWith("pirsch-meta-")){let k=s.substring(12);if(k){let O=k.split("=");O.length===2&&O[1]!==""&&(P[O[0]]=O[1].replaceAll("+"," "))}}else s.startsWith("pirsch-duration=")&&(E=Number.parseInt(s.substring(16))??0);pirsch(n,{meta:P,duration:E,non_interactive:a.classList.contains("pirsch-non-interactive")})}function Z(){let a=document.getElementsByTagName("a");for(let n of a)n.hasAttribute("href")&&!n.hasAttribute("pirsch-ignore")&&!n.hasAttribute("data-pirsch-ignore")&&!n.classList.contains("pirsch-ignore")&&(it(n.href)?S||et(n):A||tt(n))}function tt(a){let n=nt(a.href);n!==null&&n.hostname!==location.hostname&&(a.addEventListener("click",()=>pirsch(_,{meta:{url:n.href},non_interactive:!0})),a.addEventListener("auxclick",()=>pirsch(_,{meta:{url:n.href},non_interactive:!0})))}function et(a){let n=rt(a.href);a.addEventListener("click",()=>pirsch(W,{meta:{file:n},non_interactive:!0})),a.addEventListener("auxclick",()=>pirsch(W,{meta:{file:n},non_interactive:!0}))}function it(a){let n=a.split(".").pop().toLowerCase();return i.includes(n)}function nt(a){try{return new URL(a)}catch{return null}}function rt(a){try{return a.toLowerCase().startsWith("http")?new URL(a).pathname:a??"(empty)"}catch{return"(error)"}}function at(){let a=document.querySelectorAll("meta[name~='pirsch-event']");for(let n of a)if(n.hasAttribute("data-pirsch-selector")&&n.hasAttribute("data-pirsch-event")){let P=n.getAttribute("data-pirsch-trigger")||"click",E={};n.getAttributeNames().forEach(s=>{if(s.startsWith("data-pirsch-meta-")){let k=s.substring(17);k!==""&&n.getAttribute(s)!==""&&(E[k]=n.getAttribute(s))}}),document.querySelectorAll(n.getAttribute("data-pirsch-selector")).forEach(s=>{s.addEventListener(P,()=>{pirsch(n.getAttribute("data-pirsch-event"),{meta:E,non_interactive:n.hasAttribute("data-pirsch-non-interactive")})})})}}function ot(){window.pirschNotFound=function(){pirsch(K,{meta:{path:location.pathname},non_interaction:!0})}}})();})();