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