analytics/priv/tracker/js/plausible.compat.exclusions.js
Uku Taht e4b99dbad6
Fix Security error with localstorage access (#1568)
* Fix Security error with localstorage access

* Changelog
2021-12-29 11:08:11 +02:00

1 line
1.6 KiB
JavaScript

!function(){"use strict";var t,e,i,r=window.location,o=window.document,l=o.getElementById("plausible"),s=l.getAttribute("data-api")||(t=l.src.split("/"),e=t[0],i=t[2],e+"//"+i+"/api/event"),p=l&&l.getAttribute("data-exclude").split(",");function w(t){console.warn("Ignoring Event: "+t)}function n(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(r.hostname)||"file:"===r.protocol)return w("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"==window.localStorage.plausible_ignore)return w("localStorage flag")}catch(t){}if(p)for(var i=0;i<p.length;i++)if("pageview"==t&&r.pathname.match(new RegExp("^"+p[i].trim().replace(/\*\*/g,".*").replace(/([^\.])\*/g,"$1[^\\s/]*")+"/?$")))return w("exclusion rule");var n={};n.n=t,n.u=r.href,n.d=l.getAttribute("data-domain"),n.r=o.referrer||null,n.w=window.innerWidth,e&&e.meta&&(n.m=JSON.stringify(e.meta)),e&&e.props&&(n.p=JSON.stringify(e.props));var a=new XMLHttpRequest;a.open("POST",s,!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(n)),a.onreadystatechange=function(){4==a.readyState&&e&&e.callback&&e.callback()}}}var a=window.plausible&&window.plausible.q||[];window.plausible=n;for(var d,u=0;u<a.length;u++)n.apply(this,a[u]);function c(){d!==r.pathname&&(d=r.pathname,n("pageview"))}var g,h=window.history;h.pushState&&(g=h.pushState,h.pushState=function(){g.apply(this,arguments),c()},window.addEventListener("popstate",c)),"prerender"===o.visibilityState?o.addEventListener("visibilitychange",function(){d||"visible"!==o.visibilityState||c()}):c()}();