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.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
!function(){"use strict";var s=window.location,c=window.document,d=c.currentScript,u=d.getAttribute("data-api")||new URL(d.src).origin+"/api/event";function w(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 w("localStorage flag")}catch(e){}var i=d&&d.getAttribute("data-include"),a=d&&d.getAttribute("data-exclude");if("pageview"===e){var n=!i||i&&i.split(",").some(l),r=a&&a.split(",").some(l);if(!n||r)return w("exclusion rule")}var o={};o.n=e,o.u=s.href,o.d=d.getAttribute("data-domain"),o.r=c.referrer||null,o.w=window.innerWidth,t&&t.meta&&(o.m=JSON.stringify(t.meta)),t&&t.props&&(o.p=t.props),o.h=1;var p=new XMLHttpRequest;p.open("POST",u,!0),p.setRequestHeader("Content-Type","text/plain"),p.send(JSON.stringify(o)),p.onreadystatechange=function(){4===p.readyState&&t&&t.callback&&t.callback()}}function l(e){return s.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=d.getAttribute("file-types"),a=d.getAttribute("add-file-types"),o=i&&i.split(",")||a&&a.split(",").concat(t)||t;function n(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 n,r=t&&t.href&&t.href.split("?")[0];r&&(n=r.split(".").pop(),o.some(function(e){return e===n}))&&((i||a)&&plausible("File Download",{props:{url:r}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!a||(setTimeout(function(){s.href=t.href},150),e.preventDefault()))}c.addEventListener("click",n),c.addEventListener("auxclick",n);var r=window.plausible&&window.plausible.q||[];window.plausible=e;for(var p,l=0;l<r.length;l++)e.apply(this,r[l]);function g(){p=s.pathname,e("pageview")}window.addEventListener("hashchange",g),"prerender"===c.visibilityState?c.addEventListener("visibilitychange",function(){p||"visible"!==c.visibilityState||g()}):g()}(); |