mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
!function(){"use strict";var a=window.location,r=window.document,e=window.localStorage,o=r.currentScript,l=o.getAttribute("data-api")||new URL(o.src).origin+"/api/event",s=e&&e.plausible_ignore;function t(e,t){var i,n;window.phantom||window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress||("true"!=s?((i={}).n=e,i.u=a.href,i.d=o.getAttribute("data-domain"),i.r=r.referrer||null,i.w=window.innerWidth,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=JSON.stringify(t.props)),i.h=1,(n=new XMLHttpRequest).open("POST",l,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(JSON.stringify(i)),n.onreadystatechange=function(){4==n.readyState&&t&&t.callback&&t.callback()}):console.warn("Ignoring Event: localStorage flag"))}function i(e){for(var t=e.target,i="auxclick"==e.type&&2==e.which,n="click"==e.type;t&&(void 0===t.tagName||"a"!=t.tagName.toLowerCase()||!t.href);)t=t.parentNode;t&&t.href&&t.host&&t.host!==a.host&&((i||n)&&plausible("Outbound Link: Click",{props:{url:t.href}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!n||(setTimeout(function(){a.href=t.href},150),e.preventDefault()))}r.addEventListener("click",i),r.addEventListener("auxclick",i);var n=window.plausible&&window.plausible.q||[];window.plausible=t;for(var d,c=0;c<n.length;c++)t.apply(this,n[c]);function w(){d=a.pathname,t("pageview")}window.addEventListener("hashchange",w),"prerender"===r.visibilityState?r.addEventListener("visibilitychange",function(){d||"visible"!==r.visibilityState||w()}):w()}(); |