mirror of
https://github.com/plausible/analytics.git
synced 2024-11-30 00:58:54 +03:00
11654ddc07
* added data-include attribute to plausible.exclusions.js * reorder extensions in filename when serving the plausible script * fix formatting * tweaks after review * changelog update
1 line
2.1 KiB
JavaScript
1 line
2.1 KiB
JavaScript
!function(){"use strict";var t,e,i,p=window.location,c=window.document,u=c.getElementById("plausible"),d=u.getAttribute("data-api")||(t=u.src.split("/"),e=t[0],i=t[2],e+"//"+i+"/api/event");function w(t){console.warn("Ignoring Event: "+t)}function a(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(p.hostname)||"file:"===p.protocol)return w("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return w("localStorage flag")}catch(t){}var i=u&&u.getAttribute("data-include"),a=u&&u.getAttribute("data-exclude");if("pageview"===t){var n=!i||i&&i.split(",").some(s),r=a&&a.split(",").some(s);if(!n||r)return w("exclusion rule")}var o={};o.n=t,o.u=p.href,o.d=u.getAttribute("data-domain"),o.r=c.referrer||null,o.w=window.innerWidth,e&&e.meta&&(o.m=JSON.stringify(e.meta)),e&&e.props&&(o.p=e.props);var l=new XMLHttpRequest;l.open("POST",d,!0),l.setRequestHeader("Content-Type","text/plain"),l.send(JSON.stringify(o)),l.onreadystatechange=function(){4===l.readyState&&e&&e.callback&&e.callback()}}function s(t){return p.pathname.match(new RegExp("^"+t.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))}}function n(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;e&&e.href&&e.host&&e.host!==p.host&&((i||a)&&plausible("Outbound Link: Click",{props:{url:e.href}}),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()))}c.addEventListener("click",n),c.addEventListener("auxclick",n);var r=window.plausible&&window.plausible.q||[];window.plausible=a;for(var o,l=0;l<r.length;l++)a.apply(this,r[l]);function s(){o!==p.pathname&&(o=p.pathname,a("pageview"))}var h,f=window.history;f.pushState&&(h=f.pushState,f.pushState=function(){h.apply(this,arguments),s()},window.addEventListener("popstate",s)),"prerender"===c.visibilityState?c.addEventListener("visibilitychange",function(){o||"visible"!==c.visibilityState||s()}):s()}(); |