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.3 KiB
JavaScript
1 line
2.3 KiB
JavaScript
!function(){"use strict";var s=window.location,c=window.document,u=c.currentScript,d=u.getAttribute("data-api")||new URL(u.src).origin+"/api/event";function w(t){console.warn("Ignoring Event: "+t)}function t(t,e){if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return w("localStorage flag")}catch(t){}var i=u&&u.getAttribute("data-include"),a=u&&u.getAttribute("data-exclude");if("pageview"===t){var n=!i||i&&i.split(",").some(l),r=a&&a.split(",").some(l);if(!n||r)return w("exclusion rule")}var p={};p.n=t,p.u=s.href,p.d=u.getAttribute("data-domain"),p.r=c.referrer||null,p.w=window.innerWidth,e&&e.meta&&(p.m=JSON.stringify(e.meta)),e&&e.props&&(p.p=e.props);var o=new XMLHttpRequest;o.open("POST",d,!0),o.setRequestHeader("Content-Type","text/plain"),o.send(JSON.stringify(p)),o.onreadystatechange=function(){4===o.readyState&&e&&e.callback&&e.callback()}}function l(t){return s.pathname.match(new RegExp("^"+t.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))}}var e=["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=u.getAttribute("file-types"),a=u.getAttribute("add-file-types"),p=i&&i.split(",")||a&&a.split(",").concat(e)||e;function n(t){for(var e=t.target,i="auxclick"===t.type&&2===t.which,a="click"===t.type;e&&(void 0===e.tagName||"a"!==e.tagName.toLowerCase()||!e.href);)e=e.parentNode;var n,r=e&&e.href&&e.href.split("?")[0];r&&(n=r.split(".").pop(),p.some(function(t){return t===n}))&&((i||a)&&plausible("File Download",{props:{url:r}}),e.target&&!e.target.match(/^_(self|parent|top)$/i)||t.ctrlKey||t.metaKey||t.shiftKey||!a||(setTimeout(function(){s.href=e.href},150),t.preventDefault()))}c.addEventListener("click",n),c.addEventListener("auxclick",n);var r=window.plausible&&window.plausible.q||[];window.plausible=t;for(var o,l=0;l<r.length;l++)t.apply(this,r[l]);function f(){o!==s.pathname&&(o=s.pathname,t("pageview"))}var g,v=window.history;v.pushState&&(g=v.pushState,v.pushState=function(){g.apply(this,arguments),f()},window.addEventListener("popstate",f)),"prerender"===c.visibilityState?c.addEventListener("visibilitychange",function(){o||"visible"!==c.visibilityState||f()}):f()}(); |