mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 11:44:03 +03:00
11654ddc07
* added data-include attribute to plausible.exclusions.js * reorder extensions in filename when serving the plausible script * fix formatting * tweaks after review * changelog update
1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
!function(){"use strict";var p=window.location,d=window.document,w=d.currentScript,f=w.getAttribute("data-api")||new URL(w.src).origin+"/api/event";function g(e){console.warn("Ignoring Event: "+e)}function e(e,t){if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return g("localStorage flag")}catch(e){}var r=w&&w.getAttribute("data-include"),n=w&&w.getAttribute("data-exclude");if("pageview"===e){var a=!r||r&&r.split(",").some(s),i=n&&n.split(",").some(s);if(!a||i)return g("exclusion rule")}var o={};o.n=e,o.u=t&&t.u?t.u:p.href,o.d=w.getAttribute("data-domain"),o.r=d.referrer||null,o.w=window.innerWidth,t&&t.meta&&(o.m=JSON.stringify(t.meta)),t&&t.props&&(o.p=t.props);var u=w.getAttributeNames().filter(function(e){return"event-"===e.substring(0,6)}),c=o.p||{};u.forEach(function(e){var t=e.replace("event-",""),r=w.getAttribute(e);c[t]=c[t]||r}),o.p=c;var l=new XMLHttpRequest;l.open("POST",f,!0),l.setRequestHeader("Content-Type","text/plain"),l.send(JSON.stringify(o)),l.onreadystatechange=function(){4===l.readyState&&t&&t.callback&&t.callback()}}function s(e){return p.pathname.match(new RegExp("^"+e.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))}}function t(e){for(var t=e.target,r="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!==p.host&&((r||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(){p.href=t.href},150),e.preventDefault()))}d.addEventListener("click",t),d.addEventListener("auxclick",t);var r=window.plausible&&window.plausible.q||[];window.plausible=e;for(var n=0;n<r.length;n++)e.apply(this,r[n])}(); |