mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
!function(i,r){"use strict";var o,s=i.location,l=i.document,e=l.querySelector('[src*="'+r+'"]'),p=e&&e.getAttribute("data-domain");function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(s.hostname)||"file:"===s.protocol)return console.warn("Ignoring event on localhost");var n,a;i.phantom||i._phantom||i.__nightmare||i.navigator.webdriver||(console.log(o),console.log(s.pathname),o!==s.pathname&&(o=s.pathname,(n={}).n=e,n.u=s.href,n.d=p,n.r=l.referrer||null,n.w=i.innerWidth,t&&t.meta&&(n.m=JSON.stringify(t.meta)),t&&t.props&&(n.p=JSON.stringify(t.props)),n.h=1,(a=new XMLHttpRequest).open("POST",r+"/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 n(){t("pageview")}try{var a,c=i.history;c.pushState&&(a=c.pushState,c.pushState=function(){a.apply(this,arguments),n()},i.addEventListener("popstate",n)),i.addEventListener("hashchange",n);var h=i.plausible&&i.plausible.q||[];i.plausible=t;for(var u=0;u<h.length;u++)t.apply(this,h[u]);"prerender"===l.visibilityState?l.addEventListener("visibilitychange",function(){o||"visible"!==l.visibilityState||n()}):n()}catch(e){console.error(e),(new Image).src=r+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>"); |