mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
199206babc
* added the first version of dimensions extension * finished dimensions script extension + updated tracking to use it * script variants build
1 line
2.0 KiB
JavaScript
1 line
2.0 KiB
JavaScript
!function(){"use strict";var o=window.location,n=window.document,r=n.currentScript,p=r.getAttribute("data-api")||new URL(r.src).origin+"/api/event";function t(t,e){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(t){}var i={};i.n=t,i.u=o.href,i.d=r.getAttribute("data-domain"),i.r=n.referrer||null,i.w=window.innerWidth,e&&e.meta&&(i.m=JSON.stringify(e.meta)),e&&e.props&&(i.p=e.props);var a=new XMLHttpRequest;a.open("POST",p,!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(i)),a.onreadystatechange=function(){4===a.readyState&&e&&e.callback&&e.callback()}}}var e=["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=r.getAttribute("file-types"),a=r.getAttribute("add-file-types"),s=i&&i.split(",")||a&&a.split(",").concat(e)||e;function l(t){for(var e=t.target,i="auxclick"===t.type&&2===t.which,a="click"===t.type;e&&(void 0===e.tagName||"a"!==e.tagName.toLowerCase()||!e.href);)e=e.parentNode;var n,r=e&&e.href&&e.href.split("?")[0];r&&(n=r.split(".").pop(),s.some(function(t){return t===n}))&&((i||a)&&plausible("File Download",{props:{url:r}}),e.target&&!e.target.match(/^_(self|parent|top)$/i)||t.ctrlKey||t.metaKey||t.shiftKey||!a||(setTimeout(function(){o.href=e.href},150),t.preventDefault()))}n.addEventListener("click",l),n.addEventListener("auxclick",l);var d=window.plausible&&window.plausible.q||[];window.plausible=t;for(var c,w=0;w<d.length;w++)t.apply(this,d[w]);function u(){c!==o.pathname&&(c=o.pathname,t("pageview"))}var f,v=window.history;v.pushState&&(f=v.pushState,v.pushState=function(){f.apply(this,arguments),u()},window.addEventListener("popstate",u)),"prerender"===n.visibilityState?n.addEventListener("visibilitychange",function(){c||"visible"!==n.visibilityState||u()}):u()}(); |