analytics/priv/tracker/js/plausible.file-downloads.hash.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.6 KiB
JavaScript

!function(){"use strict";var o=window.location,a=window.document,n=a.currentScript,p=n.getAttribute("data-api")||new URL(n.src).origin+"/api/event";function e(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 i={};i.n=e,i.u=t&&t.u?t.u:o.href,i.d=n.getAttribute("data-domain"),i.r=a.referrer||null,i.w=window.innerWidth,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=JSON.stringify(t.props)),i.h=1;var r=new XMLHttpRequest;r.open("POST",p,!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(i)),r.onreadystatechange=function(){4==r.readyState&&t&&t.callback&&t.callback()}}}var t=n.getAttribute("file-types"),l=t&&t.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 i(e){for(var t,i,r=e.target,a="auxclick"==e.type&&2==e.which,n="click"==e.type;r&&(void 0===r.tagName||"a"!=r.tagName.toLowerCase()||!r.href);)r=r.parentNode;r&&r.href&&(t=r.href,i=t.split(".").pop(),l.some(function(e){return e==i}))&&((a||n)&&plausible("File Download",{props:{url:r.href}}),r.target&&!r.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!n||(setTimeout(function(){o.href=r.href},150),e.preventDefault()))}a.addEventListener("click",i),a.addEventListener("auxclick",i);var r=window.plausible&&window.plausible.q||[];window.plausible=e;for(var s=0;s<r.length;s++)e.apply(this,r[s])}();