mirror of
https://github.com/plausible/analytics.git
synced 2024-11-30 00:58:54 +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 e,t,i,s=window.location,c=window.document,d=c.getElementById("plausible"),u=d.getAttribute("data-api")||(e=d.src.split("/"),t=e[0],i=e[2],t+"//"+i+"/api/event");function w(e){console.warn("Ignoring Event: "+e)}function a(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 n=["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"],r=d.getAttribute("file-types"),o=d.getAttribute("add-file-types"),p=r&&r.split(",")||o&&o.split(",").concat(n)||n;function l(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(),p.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",l),c.addEventListener("auxclick",l);var g=window.plausible&&window.plausible.q||[];window.plausible=a;for(var f,v=0;v<g.length;v++)a.apply(this,g[v]);function m(){f=s.pathname,a("pageview")}window.addEventListener("hashchange",m),"prerender"===c.visibilityState?c.addEventListener("visibilitychange",function(){f||"visible"!==c.visibilityState||m()}):m()}(); |