mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 19:15:03 +03:00
96633f46b1
* Swaps to Negative Lookbehind for exclude Regex * Updates to not use negative lookbehind
1 line
1.2 KiB
JavaScript
1 line
1.2 KiB
JavaScript
!function(r,i){"use strict";var e,o=r.location,s=r.document,t=s.querySelector('[src*="'+i+'"]'),l=t&&t.getAttribute("data-domain"),c=r.localStorage.plausible_ignore;function p(e){console.warn("Ignoring Event: "+e)}function n(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(o.hostname)||"file:"===o.protocol)return p("localhost");if(!(r.phantom||r._phantom||r.__nightmare||r.navigator.webdriver||r.Cypress)){if("true"==c)return p("localStorage flag");var n={};n.n=e,n.u=o.href,n.d=l,n.r=s.referrer||null,n.w=r.innerWidth,t&&t.meta&&(n.m=JSON.stringify(t.meta)),t&&t.props&&(n.p=JSON.stringify(t.props)),n.h=1;var a=new XMLHttpRequest;a.open("POST",i+"/api/event",!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(n)),a.onreadystatechange=function(){4==a.readyState&&t&&t.callback&&t.callback()}}}function a(){e=o.pathname,n("pageview")}try{r.addEventListener("hashchange",a);var u=r.plausible&&r.plausible.q||[];r.plausible=n;for(var g=0;g<u.length;g++)n.apply(this,u[g]);"prerender"===s.visibilityState?s.addEventListener("visibilitychange",function(){e||"visible"!==s.visibilityState||a()}):a()}catch(e){console.error(e),(new Image).src=i+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>"); |