analytics/priv/tracker/js/plausible.compat.file-downloads.hash.local.manual.outbound-links.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
2.1 KiB
JavaScript

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