mirror of
https://github.com/plausible/analytics.git
synced 2024-12-28 12:01:39 +03:00
e4b99dbad6
* Fix Security error with localstorage access * Changelog
1 line
1.1 KiB
JavaScript
1 line
1.1 KiB
JavaScript
!function(){"use strict";var e,t,i,a=window.location,r=window.document,o=r.getElementById("plausible"),l=o.getAttribute("data-api")||(e=o.src.split("/"),t=e[0],i=e[2],t+"//"+i+"/api/event");function n(e,t){if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"==window.localStorage.plausible_ignore)return void console.warn("Ignoring Event: localStorage flag")}catch(e){}var i={};i.n=e,i.u=a.href,i.d=o.getAttribute("data-domain"),i.r=r.referrer||null,i.w=window.innerWidth,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=JSON.stringify(t.props)),i.h=1;var n=new XMLHttpRequest;n.open("POST",l,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(JSON.stringify(i)),n.onreadystatechange=function(){4==n.readyState&&t&&t.callback&&t.callback()}}}var d=window.plausible&&window.plausible.q||[];window.plausible=n;for(var s,w=0;w<d.length;w++)n.apply(this,d[w]);function p(){s=a.pathname,n("pageview")}window.addEventListener("hashchange",p),"prerender"===r.visibilityState?r.addEventListener("visibilitychange",function(){s||"visible"!==r.visibilityState||p()}):p()}(); |