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