analytics/priv/tracker/js/plausible.compat.exclusions.file-downloads.local.manual.js
RobertJoonas 8616dd46fb
added file-downloads script extension (#1775)
* added file-downloads script extension

* fixed the issues and made it compatible with IE

* changelog update
2022-03-31 13:52:09 +03:00

1 line
1.9 KiB
JavaScript

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