mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 17:44:43 +03:00
e80fc7bb8e
* Use `document.currentScript` to get script host * Add data-api
1 line
1.4 KiB
JavaScript
1 line
1.4 KiB
JavaScript
!function(){"use strict";var e,r=window.location,o=window.document,l=o.currentScript,s=new URL(l.src).origin,w=window.localStorage.plausible_ignore,c=l&&l.getAttribute("data-exclude").split(",");function p(e){console.warn("Ignoring Event: "+e)}function i(e,i){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(r.hostname)||"file:"===r.protocol)return p("localhost");if(!(window.phantom||window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){if("true"==w)return p("localStorage flag");if(c)for(var n=0;n<c.length;n++)if("pageview"==e&&r.pathname.match(new RegExp("^"+c[n].trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$")))return p("exclusion rule");var t={};t.n=e,t.u=r.href,t.d=l.id,t.r=o.referrer||null,t.w=window.innerWidth,i&&i.meta&&(t.m=JSON.stringify(i.meta)),i&&i.props&&(t.p=JSON.stringify(i.props)),t.h=1;var a=new XMLHttpRequest;a.open("POST",s+"/api/event",!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(t)),a.onreadystatechange=function(){4==a.readyState&&i&&i.callback&&i.callback()}}}function n(){e=r.pathname,i("pageview")}window.addEventListener("hashchange",n);var t=window.plausible&&window.plausible.q||[];window.plausible=i;for(var a=0;a<t.length;a++)i.apply(this,t[a]);"prerender"===o.visibilityState?o.addEventListener("visibilitychange",function(){e||"visible"!==o.visibilityState||n()}):n()}(); |