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