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