mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 11:44:03 +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.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
!function(){"use strict";var t,e,i,o=window.location,l=window.document,p=l.getElementById("plausible"),s=p.getAttribute("data-api")||(t=p.src.split("/"),e=t[0],i=t[2],e+"//"+i+"/api/event");function c(t){console.warn("Ignoring Event: "+t)}function a(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(o.hostname)||"file:"===o.protocol)return c("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return c("localStorage flag")}catch(t){}var i={};i.n=t,i.u=o.href,i.d=p.getAttribute("data-domain"),i.r=l.referrer||null,i.w=window.innerWidth,e&&e.meta&&(i.m=JSON.stringify(e.meta)),e&&e.props&&(i.p=e.props);var a=p.getAttributeNames().filter(function(t){return"event-"===t.substring(0,6)}),n=i.p||{};a.forEach(function(t){var e=t.replace("event-",""),i=p.getAttribute(t);n[e]=n[e]||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&&e&&e.callback&&e.callback()}}}var n=["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"],r=p.getAttribute("file-types"),d=p.getAttribute("add-file-types"),u=r&&r.split(",")||d&&d.split(",").concat(n)||n;function f(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(),u.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()))}l.addEventListener("click",f),l.addEventListener("auxclick",f);var w=window.plausible&&window.plausible.q||[];window.plausible=a;for(var v,g=0;g<w.length;g++)a.apply(this,w[g]);function h(){v=o.pathname,a("pageview")}window.addEventListener("hashchange",h),"prerender"===l.visibilityState?l.addEventListener("visibilitychange",function(){v||"visible"!==l.visibilityState||h()}):h()}(); |