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.4 KiB
JavaScript
1 line
2.4 KiB
JavaScript
!function(){"use strict";var t,e,i,s=window.location,c=window.document,u=c.getElementById("plausible"),d=u.getAttribute("data-api")||(t=u.src.split("/"),e=t[0],i=t[2],e+"//"+i+"/api/event");function w(t){console.warn("Ignoring Event: "+t)}function a(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(s.hostname)||"file:"===s.protocol)return w("localhost");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 o={};o.n=t,o.u=s.href,o.d=u.getAttribute("data-domain"),o.r=c.referrer||null,o.w=window.innerWidth,e&&e.meta&&(o.m=JSON.stringify(e.meta)),e&&e.props&&(o.p=e.props);var p=new XMLHttpRequest;p.open("POST",d,!0),p.setRequestHeader("Content-Type","text/plain"),p.send(JSON.stringify(o)),p.onreadystatechange=function(){4===p.readyState&&e&&e.callback&&e.callback()}}function l(t){return s.pathname.match(new RegExp("^"+t.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=u.getAttribute("file-types"),o=u.getAttribute("add-file-types"),p=r&&r.split(",")||o&&o.split(",").concat(n)||n;function l(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",l),c.addEventListener("auxclick",l);var f=window.plausible&&window.plausible.q||[];window.plausible=a;for(var g,v=0;v<f.length;v++)a.apply(this,f[v]);function h(){g!==s.pathname&&(g=s.pathname,a("pageview"))}var m,y=window.history;y.pushState&&(m=y.pushState,y.pushState=function(){m.apply(this,arguments),h()},window.addEventListener("popstate",h)),"prerender"===c.visibilityState?c.addEventListener("visibilitychange",function(){g||"visible"!==c.visibilityState||h()}):h()}(); |