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 e,t,n,i=window.location,r=window.document,a=window.localStorage,o=r.getElementById("plausible"),l=o.getAttribute("data-api")||(e=o.src.split("/"),t=e[0],n=e[2],t+"//"+n+"/api/event"),s=a&&a.plausible_ignore;function c(e){console.warn("Ignoring Event: "+e)}function p(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(i.hostname)||"file:"===i.protocol)return c("localhost");if(!(window.phantom||window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){if("true"==s)return c("localStorage flag");var n={};n.n=e,n.u=i.href,n.d=o.getAttribute("data-domain"),n.r=r.referrer||null,n.w=window.innerWidth,t&&t.meta&&(n.m=JSON.stringify(t.meta)),t&&t.props&&(n.p=JSON.stringify(t.props)),n.h=1;var a=new XMLHttpRequest;a.open("POST",l,!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(n)),a.onreadystatechange=function(){4==a.readyState&&t&&t.callback&&t.callback()}}}function d(e){for(var t=e.target,n="auxclick"==e.type&&2==e.which,a="click"==e.type;t&&(void 0===t.tagName||"a"!=t.tagName.toLowerCase()||!t.href);)t=t.parentNode;t&&t.href&&t.host&&t.host!==i.host&&((n||a)&&plausible("Outbound Link: Click",{props:{url:t.href}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!a||(setTimeout(function(){i.href=t.href},150),e.preventDefault()))}r.addEventListener("click",d),r.addEventListener("auxclick",d);var u=window.plausible&&window.plausible.q||[];window.plausible=p;for(var w=0;w<u.length;w++)p.apply(this,u[w])}(); |