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
2.5 KiB
JavaScript
1 line
2.5 KiB
JavaScript
!function(){"use strict";var u=window.location,d=window.document,f=d.currentScript,w=f.getAttribute("data-api")||new URL(f.src).origin+"/api/event";function g(e){console.warn("Ignoring Event: "+e)}function e(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(u.hostname)||"file:"===u.protocol)return g("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return g("localStorage flag")}catch(e){}var i=f&&f.getAttribute("data-include"),a=f&&f.getAttribute("data-exclude");if("pageview"===e){var r=!i||i&&i.split(",").some(c),n=a&&a.split(",").some(c);if(!r||n)return g("exclusion rule")}var o={};o.n=e,o.u=u.href,o.d=f.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 l=f.getAttributeNames().filter(function(e){return"event-"===e.substring(0,6)}),p=o.p||{};l.forEach(function(e){var t=e.replace("event-",""),i=f.getAttribute(e);p[t]=p[t]||i}),o.p=p,o.h=1;var s=new XMLHttpRequest;s.open("POST",w,!0),s.setRequestHeader("Content-Type","text/plain"),s.send(JSON.stringify(o)),s.onreadystatechange=function(){4===s.readyState&&t&&t.callback&&t.callback()}}function c(e){return u.pathname.match(new RegExp("^"+e.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))}}var t=["pdf","xlsx","docx","txt","rtf","csv","exe","key","pps","ppt","pptx","7z","pkg","rar","gz","zip","avi","mov","mp4","mpeg","wmv","midi","mp3","wav","wma"],i=f.getAttribute("file-types"),a=f.getAttribute("add-file-types"),o=i&&i.split(",")||a&&a.split(",").concat(t)||t;function r(e){for(var t=e.target,i="auxclick"===e.type&&2===e.which,a="click"===e.type;t&&(void 0===t.tagName||"a"!==t.tagName.toLowerCase()||!t.href);)t=t.parentNode;var r,n=t&&t.href&&t.href.split("?")[0];n&&(r=n.split(".").pop(),o.some(function(e){return e===r}))&&((i||a)&&plausible("File Download",{props:{url:n}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!a||(setTimeout(function(){u.href=t.href},150),e.preventDefault()))}d.addEventListener("click",r),d.addEventListener("auxclick",r);var n=window.plausible&&window.plausible.q||[];window.plausible=e;for(var l,p=0;p<n.length;p++)e.apply(this,n[p]);function s(){l=u.pathname,e("pageview")}window.addEventListener("hashchange",s),"prerender"===d.visibilityState?d.addEventListener("visibilitychange",function(){l||"visible"!==d.visibilityState||s()}):s()}(); |