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