mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 02:55:02 +03:00
8616dd46fb
* added file-downloads script extension * fixed the issues and made it compatible with IE * changelog update
1 line
1.7 KiB
JavaScript
1 line
1.7 KiB
JavaScript
!function(){"use strict";var e,t,a,o=window.location,r=window.document,n=r.getElementById("plausible"),l=n.getAttribute("data-api")||(e=n.src.split("/"),t=e[0],a=e[2],t+"//"+a+"/api/event");function p(e){console.warn("Ignoring Event: "+e)}function i(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(o.hostname)||"file:"===o.protocol)return p("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"==window.localStorage.plausible_ignore)return p("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));var i=new XMLHttpRequest;i.open("POST",l,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(a)),i.onreadystatechange=function(){4==i.readyState&&t&&t.callback&&t.callback()}}}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 w=0;w<u.length;w++)i.apply(this,u[w])}(); |