(()=>{function $(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 j(t){return window.localStorage!==void 0&&window.localStorage.getItem("disable_pirsch")||ot(t)||!st(t)||ct(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 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 N(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 ot(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 st(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:x,disableResolution:P,stripAnchor:A}=t;M({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,stripAnchor:A});for(let d=0;d`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:n,pathPrefix:o,pathSuffix:u,titlePrefix:l,titleSuffix:f,identificationCode:c,endpoint:m,disableQueryParams:g,disableReferrer:x,disableResolution:P,stripAnchor:A}=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 v=b&&b.meta?b.meta:{};for(let h in v)v.hasOwnProperty(h)&&(v[h]=String(v[h]));z({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,stripAnchor:A,name:d,options:b,meta:v,non_interactive:t.non_interactive,resolve:w,reject:y});for(let h=0;h{dt({domains:e,rewrite:n,pathPrefix:o,pathSuffix:u,identificationCode:l,endpoint:f,disableQueryParams:c})},m);window.pirschClearSession=()=>{clearInterval(g)}}function dt(t){let{domains:i,rewrite:e,pathPrefix:n,pathSuffix:o,identificationCode:u,endpoint:l,disableQueryParams:f}=t;X({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{W(S)}),S.addEventListener("auxclick",()=>{W(S)})}function W(r){let a=r.getAttribute("pirsch-event")??r.getAttribute("data-pirsch-event");if(!a){console.error("Pirsch event attribute name can not be empty!",r);return}let S={},L;for(let p of r.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"))&&(L=Number.parseInt(p.value,10)??0);pirsch(a,{meta:S,duration:L,non_interactive:r.hasAttribute("pirsch-non-interactive")||r.hasAttribute("data-pirsch-non-interactive")})}function Y(){let r=document.querySelectorAll("[class*='pirsch-event=']");for(let a of r)a.addEventListener("click",()=>{D(a)}),a.addEventListener("auxclick",()=>{D(a)})}function D(r){let a="",S={},L;for(let p of r.classList)if(p.startsWith("pirsch-event=")){if(a=p.substring(13).replaceAll("+"," "),!a){console.error("Pirsch event class name can not be empty!",r);return}}else if(p.startsWith("pirsch-meta-")){let F=p.substring(12);if(F){let _=F.split("=");_.length===2&&_[1]!==""&&(S[_[0]]=_[1].replaceAll("+"," "))}}else p.startsWith("pirsch-duration=")&&(L=Number.parseInt(p.substring(16))??0);pirsch(a,{meta:S,duration:L,non_interactive:r.classList.contains("pirsch-non-interactive")})}function Z(){let r=document.getElementsByTagName("a");for(let a of r)!a.hasAttribute("pirsch-ignore")&&!a.hasAttribute("data-pirsch-ignore")&&!a.classList.contains("pirsch-ignore")&&(it(a.href)?A||et(a):P||tt(a))}function tt(r){let a=nt(r.href);a!==null&&a.hostname!==location.hostname&&(r.addEventListener("click",()=>pirsch(k,{meta:{url:a.href},non_interactive:!0})),r.addEventListener("auxclick",()=>pirsch(k,{meta:{url:a.href},non_interactive:!0})))}function et(r){let a=rt(r.href);r.addEventListener("click",()=>pirsch(q,{meta:{file:a},non_interactive:!0})),r.addEventListener("auxclick",()=>pirsch(q,{meta:{file:a},non_interactive:!0}))}function it(r){let a=r.split(".").pop().toLowerCase();return i.includes(a)}function nt(r){try{return new URL(r)}catch{return null}}function rt(r){try{return r.toLowerCase().startsWith("http")?new URL(r).pathname:r??"(empty)"}catch{return"(error)"}}function at(){window.pirschNotFound=function(){pirsch(K,{meta:{path:location.pathname},non_interaction:!0})}}})();})();