Files
mermaid-live-editor/_app/immutable/chunks/plausible.6fa318ff.js
T
2023-06-14 17:28:48 +00:00

2 lines
2.9 KiB
JavaScript

function b(s,e,n){const o=/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*:)*?:?0*1$/.test(location.hostname)||location.protocol==="file:";if(!e.trackLocalhost&&o)return console.warn("[Plausible] Ignoring event because website is running locally");try{if(window.localStorage.plausible_ignore==="true")return console.warn('[Plausible] Ignoring event because "plausible_ignore" is set to "true" in localStorage')}catch{}const f={n:s,u:e.url,d:e.domain,r:e.referrer,w:e.deviceWidth,h:e.hashMode?1:0,p:n&&n.props?JSON.stringify(n.props):void 0},l=new XMLHttpRequest;l.open("POST",`${e.apiHost}/api/event`,!0),l.setRequestHeader("Content-Type","text/plain"),l.send(JSON.stringify(f)),l.onreadystatechange=()=>{l.readyState===4&&n&&n.callback&&n.callback()}}function g(s){const e=()=>({hashMode:!1,trackLocalhost:!1,url:location.href,domain:location.hostname,referrer:document.referrer||null,deviceWidth:window.innerWidth,apiHost:"https://plausible.io",...s}),n=(r,i,a)=>{b(r,{...e(),...a},i)},o=(r,i)=>{n("pageview",i,r)};return{trackEvent:n,trackPageview:o,enableAutoPageviews:()=>{const r=()=>o(),i=history.pushState;return i&&(history.pushState=function(a,c,h){i.apply(this,[a,c,h]),r()},addEventListener("popstate",r)),s&&s.hashMode&&addEventListener("hashchange",r),o(),function(){i&&(history.pushState=i,removeEventListener("popstate",r)),s&&s.hashMode&&removeEventListener("hashchange",r)}},enableAutoOutboundTracking:(r=document,i={subtree:!0,childList:!0,attributes:!0,attributeFilter:["href"]})=>{function a(t){n("Outbound Link: Click",{props:{url:this.href}}),typeof process<"u"&&process,setTimeout(()=>{location.href=this.href},150),t.preventDefault()}const c=new Set;function h(t){t instanceof HTMLAnchorElement?t.host!==location.host&&(t.addEventListener("click",a),c.add(t)):"querySelectorAll"in t&&t.querySelectorAll("a").forEach(h)}function p(t){t instanceof HTMLAnchorElement?(t.removeEventListener("click",a),c.delete(t)):"querySelectorAll"in t&&t.querySelectorAll("a").forEach(p)}const d=new MutationObserver(t=>{t.forEach(u=>{u.type==="attributes"?(p(u.target),h(u.target)):u.type==="childList"&&(u.addedNodes.forEach(h),u.removedNodes.forEach(p))})});return r.querySelectorAll("a").forEach(h),d.observe(r,i),function(){c.forEach(u=>{u.removeEventListener("click",a)}),c.clear(),d.disconnect()}}}}const v={enabled:!0};function k(s){const e={plausible:null};return{name:"plausible-analytics",config:{...v,...s},initialize:({config:n})=>{const{apiHost:o,domain:f,hashMode:l,trackLocalhost:r,outboundLinkTracking:i}=n,a=Object.fromEntries(Object.entries({apiHost:o,domain:f,hashMode:l,trackLocalhost:r}).filter(([,c])=>c!==void 0));e.plausible=g(a),i&&e.plausible.enableAutoOutboundTracking()},loaded:()=>!!e.plausible,page:({payload:n})=>{if(!e.plausible)return;const{properties:o}=n;e.plausible.trackPageview({},{props:o})},track:({payload:n})=>{if(!e.plausible)return;const{properties:o,event:f}=n;e.plausible.trackEvent(f,{props:o})}}}export{k as default};