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