analytics/priv/tracker/js/plausible.dimensions.file-downloads.hash.local.js
RobertJoonas 199206babc
Dimensions continued (#1847)
* added the first version of dimensions extension

* finished dimensions script extension + updated tracking to use it

* script variants build
2022-04-25 10:56:11 +03:00

1 line
2.0 KiB
JavaScript

!function(){"use strict";var o=window.location,p=window.document,l=p.currentScript,s=l.getAttribute("data-api")||new URL(l.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=o.href,i.d=l.getAttribute("data-domain"),i.r=p.referrer||null,i.w=window.innerWidth,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=t.props);var a=l.getAttributeNames().filter(function(e){return"event-"===e.substring(0,6)}),n=i.p||{};a.forEach(function(e){var t=e.replace("event-",""),i=l.getAttribute(e);n[t]=n[t]||i}),i.p=n,i.h=1;var r=new XMLHttpRequest;r.open("POST",s,!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=["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"],i=l.getAttribute("file-types"),a=l.getAttribute("add-file-types"),c=i&&i.split(",")||a&&a.split(",").concat(t)||t;function n(e){for(var t=e.target,i="auxclick"===e.type&&2===e.which,a="click"===e.type;t&&(void 0===t.tagName||"a"!==t.tagName.toLowerCase()||!t.href);)t=t.parentNode;var n,r=t&&t.href&&t.href.split("?")[0];r&&(n=r.split(".").pop(),c.some(function(e){return e===n}))&&((i||a)&&plausible("File Download",{props:{url:r}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!a||(setTimeout(function(){o.href=t.href},150),e.preventDefault()))}p.addEventListener("click",n),p.addEventListener("auxclick",n);var r=window.plausible&&window.plausible.q||[];window.plausible=e;for(var d,u=0;u<r.length;u++)e.apply(this,r[u]);function w(){d=o.pathname,e("pageview")}window.addEventListener("hashchange",w),"prerender"===p.visibilityState?p.addEventListener("visibilitychange",function(){d||"visible"!==p.visibilityState||w()}):w()}();