(()=>{function F(t){let i=document.querySelector(t);if(!i)throw`Pirsch script ${t} tag not found!`;return i}function s(t,i){let e="";return t.length>0&&(i{n=n.trim().replaceAll("-"," "),n&&(i[n]="1")});return i}function $(t){return localStorage.getItem("disable_pirsch")||at(t)||!ot(t)||st(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 n=new URL(t);return n.pathname=i+n.pathname+e,n.toString()}function I(t,i){let e=document.title;return t||(t=""),i||(i=""),t+e+i}function N(t){let i=document.referrer;return t&&(i=i.replace(location.hostname,t)),i}function _(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 at(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 ot(t){try{let i=t.getAttribute("data-include"),e=i?i.split(","):[];if(e.length){let n=!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:n,pathPrefix:o,pathSuffix:u,titlePrefix:l,titleSuffix:f,identificationCode:c,endpoint:m,disableQueryParams:g,disableReferrer:v,disableResolution:P,stripAnchor:S}=t;j({script:i,hostname:n,pathPrefix:e.length?"":s(o,0),pathSuffix:e.length?"":s(u,0),titlePrefix:e.length?"":s(l,0),titleSuffix:e.length?"":s(f,0),identificationCode:c,endpoint:m,disableQueryParams:g,disableReferrer:v,disableResolution:P,stripAnchor:S});for(let d=0;d`tag_${y.replaceAll("-"," ")}=${x||1}`).join("&"):""),w=new XMLHttpRequest;w.open("GET",b),w.send()}function z(){window.pirsch=function(t,i){return console.log(`Pirsch event: ${t}${i?" "+JSON.stringify(i):""}`),Promise.resolve(null)}}function B(t){let{script:i,domains:e,rewrite:n,pathPrefix:o,pathSuffix:u,titlePrefix:l,titleSuffix:f,identificationCode:c,endpoint:m,disableQueryParams:g,disableReferrer:v,disableResolution:P,stripAnchor:S}=t;window.pirsch=function(d,b){return typeof d!="string"||!d?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 x=b&&b.meta?b.meta:{};for(let h in x)x.hasOwnProperty(h)&&(x[h]=String(x[h]));V({script:i,hostname:n,pathPrefix:e.length?"":s(o,0),pathSuffix:e.length?"":s(u,0),titlePrefix:e.length?"":s(l,0),titleSuffix:e.length?"":s(f,0),identificationCode:c,endpoint:m,disableQueryParams:g,disableReferrer:v,disableResolution:P,stripAnchor:S,name:d,options:b,meta:x,non_interactive:t.non_interactive,resolve:w,reject:y});for(let h=0;h{ct({domains:e,rewrite:n,pathPrefix:o,pathSuffix:u,identificationCode:l,endpoint:f,disableQueryParams:c})},m);window.pirschClearSession=()=>{clearInterval(g)}}function ct(t){let{domains:i,rewrite:e,pathPrefix:n,pathSuffix:o,identificationCode:u,endpoint:l,disableQueryParams:f}=t;J({hostname:e,pathPrefix:i.length?"":s(n,0),pathSuffix:i.length?"":s(o,0),identificationCode:u,endpoint:l,disableQueryParams:f});for(let c=0;c{H(A)}),A.addEventListener("auxclick",()=>{H(A)})}function H(a){let r=a.getAttribute("pirsch-event")??a.getAttribute("data-pirsch-event");if(!r){console.error("Pirsch event attribute name can not be empty!",a);return}let A={},L;for(let p of a.attributes)p.name.startsWith("data-pirsch-meta-")?A[p.name.substring(17)]=p.value:p.name.startsWith("pirsch-meta-")?A[p.name.substring(12)]=p.value:(p.name.startsWith("data-pirsch-duration")||p.name.startsWith("pirsch-duration"))&&(L=Number.parseInt(p.value,10)??0);pirsch(r,{meta:A,duration:L})}function K(){let a=document.querySelectorAll("[class*='pirsch-event=']");for(let r of a)r.addEventListener("click",()=>{W(r)}),r.addEventListener("auxclick",()=>{W(r)})}function W(a){let r="",A={},L;for(let p of a.classList)if(p.startsWith("pirsch-event=")){if(r=p.substring(13).replaceAll("+"," "),!r){console.error("Pirsch event class name can not be empty!",a);return}}else if(p.startsWith("pirsch-meta-")){let D=p.substring(12);if(D){let O=D.split("=");O.length===2&&O[1]!==""&&(A[O[0]]=O[1].replaceAll("+"," "))}}else p.startsWith("pirsch-duration=")&&(L=Number.parseInt(p.substring(16))??0);pirsch(r,{meta:A,duration:L})}function Y(){let a=document.getElementsByTagName("a");for(let r of a)!r.hasAttribute("pirsch-ignore")&&!r.hasAttribute("data-pirsch-ignore")&&!r.classList.contains("pirsch-ignore")&&(et(r.href)?S||tt(r):P||Z(r))}function Z(a){let r=it(a.href);r!==null&&r.hostname!==location.hostname&&(a.addEventListener("click",()=>pirsch(E,{meta:{url:r.href}})),a.addEventListener("auxclick",()=>pirsch(E,{meta:{url:r.href}})))}function tt(a){let r=nt(a.href);a.addEventListener("click",()=>pirsch(k,{meta:{file:r}})),a.addEventListener("auxclick",()=>pirsch(k,{meta:{file:r}}))}function et(a){let r=a.split(".").pop().toLowerCase();return i.includes(r)}function it(a){try{return new URL(a)}catch{return null}}function nt(a){try{return a.toLowerCase().startsWith("http")?new URL(a).pathname:a??"(empty)"}catch{return"(error)"}}function rt(){window.pirschNotFound=function(){pirsch(G,{meta:{path:location.pathname}})}}})();})();