mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 11:44:03 +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
1.6 KiB
JavaScript
1 line
1.6 KiB
JavaScript
!function(){"use strict";var e,t,i,c=window.location,d=window.document,w=d.getElementById("plausible"),g=w.getAttribute("data-api")||(e=w.src.split("/"),t=e[0],i=e[2],t+"//"+i+"/api/event");function v(e){console.warn("Ignoring Event: "+e)}function n(e,t){if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return v("localStorage flag")}catch(e){}var i=w&&w.getAttribute("data-include"),n=w&&w.getAttribute("data-exclude");if("pageview"===e){var a=!i||i&&i.split(",").some(p),r=n&&n.split(",").some(p);if(!a||r)return v("exclusion rule")}var o={};o.n=e,o.u=c.href,o.d=w.getAttribute("data-domain"),o.r=d.referrer||null,o.w=window.innerWidth,t&&t.meta&&(o.m=JSON.stringify(t.meta)),t&&t.props&&(o.p=t.props);var l=w.getAttributeNames().filter(function(e){return"event-"===e.substring(0,6)}),s=o.p||{};l.forEach(function(e){var t=e.replace("event-",""),i=w.getAttribute(e);s[t]=s[t]||i}),o.p=s,o.h=1;var u=new XMLHttpRequest;u.open("POST",g,!0),u.setRequestHeader("Content-Type","text/plain"),u.send(JSON.stringify(o)),u.onreadystatechange=function(){4===u.readyState&&t&&t.callback&&t.callback()}}function p(e){return c.pathname.match(new RegExp("^"+e.trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$"))}}var a=window.plausible&&window.plausible.q||[];window.plausible=n;for(var r,o=0;o<a.length;o++)n.apply(this,a[o]);function l(){r=c.pathname,n("pageview")}window.addEventListener("hashchange",l),"prerender"===d.visibilityState?d.addEventListener("visibilitychange",function(){r||"visible"!==d.visibilityState||l()}):l()}(); |