mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 18:48:06 +03:00
a7eab3f17b
Fixes #1225
1 line
1.7 KiB
JavaScript
1 line
1.7 KiB
JavaScript
!function(){"use strict";var t,e,i,a,n=window.location,r=window.document,o=window.localStorage,s=r.getElementById("plausible"),l=s.getAttribute("data-api")||(t=s.src.split("/"),e=t[0],i=t[2],e+"//"+i+"/api/event"),p=o&&o.plausible_ignore;function d(t,e){var i,a;window.phantom||window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress||("true"!=p?((i={}).n=t,i.u=n.href,i.d=s.getAttribute("data-domain"),i.r=r.referrer||null,i.w=window.innerWidth,e&&e.meta&&(i.m=JSON.stringify(e.meta)),e&&e.props&&(i.p=JSON.stringify(e.props)),(a=new XMLHttpRequest).open("POST",l,!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(i)),a.onreadystatechange=function(){4==a.readyState&&e&&e.callback&&e.callback()}):console.warn("Ignoring Event: localStorage flag"))}function w(){a!==n.pathname&&(a=n.pathname,d("pageview"))}function c(t){for(var e=t.target,i="auxclick"==t.type&&2==t.which,a="click"==t.type;e&&(void 0===e.tagName||"a"!=e.tagName.toLowerCase()||!e.href);)e=e.parentNode;e&&e.href&&e.host&&e.host!==n.host&&((i||a)&&plausible("Outbound Link: Click",{props:{url:e.href}}),e.target&&!e.target.match(/^_(self|parent|top)$/i)||t.ctrlKey||t.metaKey||t.shiftKey||!a||(setTimeout(function(){n.href=e.href},150),t.preventDefault()))}var u,h=window.history;h.pushState&&(u=h.pushState,h.pushState=function(){u.apply(this,arguments),w()},window.addEventListener("popstate",w)),r.addEventListener("click",c),r.addEventListener("auxclick",c);var f=window.plausible&&window.plausible.q||[];window.plausible=d;for(var g=0;g<f.length;g++)d.apply(this,f[g]);"prerender"===r.visibilityState?r.addEventListener("visibilitychange",function(){a||"visible"!==r.visibilityState||w()}):w()}(); |