analytics/priv/tracker/js/plausible.exclusions.js
Vignesh Joglekar 96633f46b1
Fixes exclude regex eating one character before single * (#861)
* Swaps to Negative Lookbehind for exclude Regex

* Updates to not use negative lookbehind
2021-03-22 15:44:53 +02:00

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 %>");