analytics/priv/tracker/js/plausible.compat.dimensions.exclusions.file-downloads.manual.outbound-links.js
RobertJoonas 11654ddc07
Script extension additions (#1915)
* added data-include attribute to plausible.exclusions.js

* reorder extensions in filename when serving the plausible script

* fix formatting

* tweaks after review

* changelog update
2022-05-27 10:11:40 +03:00

1 line
2.8 KiB
JavaScript

!function(){"use strict";var e,t,a,u=window.location,f=window.document,d=f.getElementById("plausible"),g=d.getAttribute("data-api")||(e=d.src.split("/"),t=e[0],a=e[2],t+"//"+a+"/api/event");function w(e){console.warn("Ignoring Event: "+e)}function r(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(u.hostname)||"file:"===u.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(e){}var a=d&&d.getAttribute("data-include"),r=d&&d.getAttribute("data-exclude");if("pageview"===e){var i=!a||a&&a.split(",").some(s),n=r&&r.split(",").some(s);if(!i||n)return w("exclusion rule")}var o={};o.n=e,o.u=t&&t.u?t.u:u.href,o.d=d.getAttribute("data-domain"),o.r=f.referrer||null,o.w=window.innerWidth,t&&t.meta&&(o.m=JSON.stringify(t.meta)),t&&t.props&&(o.p=t.props);var l=d.getAttributeNames().filter(function(e){return"event-"===e.substring(0,6)}),p=o.p||{};l.forEach(function(e){var t=e.replace("event-",""),a=d.getAttribute(e);p[t]=p[t]||a}),o.p=p;var c=new XMLHttpRequest;c.open("POST",g,!0),c.setRequestHeader("Content-Type","text/plain"),c.send(JSON.stringify(o)),c.onreadystatechange=function(){4===c.readyState&&t&&t.callback&&t.callback()}}function s(e){return u.pathname.match(new RegExp("^"+e.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))}}function i(e){for(var t=e.target,a="auxclick"===e.type&&2===e.which,r="click"===e.type;t&&(void 0===t.tagName||"a"!==t.tagName.toLowerCase()||!t.href);)t=t.parentNode;t&&t.href&&t.host&&t.host!==u.host&&((a||r)&&plausible("Outbound Link: Click",{props:{url:t.href}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!r||(setTimeout(function(){u.href=t.href},150),e.preventDefault()))}f.addEventListener("click",i),f.addEventListener("auxclick",i);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"],o=d.getAttribute("file-types"),l=d.getAttribute("add-file-types"),p=o&&o.split(",")||l&&l.split(",").concat(n)||n;function c(e){for(var t=e.target,a="auxclick"===e.type&&2===e.which,r="click"===e.type;t&&(void 0===t.tagName||"a"!==t.tagName.toLowerCase()||!t.href);)t=t.parentNode;var i,n=t&&t.href&&t.href.split("?")[0];n&&(i=n.split(".").pop(),p.some(function(e){return e===i}))&&((a||r)&&plausible("File Download",{props:{url:n}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!r||(setTimeout(function(){u.href=t.href},150),e.preventDefault()))}f.addEventListener("click",c),f.addEventListener("auxclick",c);var s=window.plausible&&window.plausible.q||[];window.plausible=r;for(var h=0;h<s.length;h++)r.apply(this,s[h])}();