analytics/priv/tracker/js/plausible.compat.dimensions.local.outbound-links.js

1 line
1.9 KiB
JavaScript
Raw Normal View History

!function(){"use strict";var t,e,i,o=window.location,s=window.document,l=s.getElementById("plausible"),p=l.getAttribute("data-api")||(t=l.src.split("/"),e=t[0],i=t[2],e+"//"+i+"/api/event");function a(t,e){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(t){}var i={};i.n=t,i.u=o.href,i.d=l.getAttribute("data-domain"),i.r=s.referrer||null,i.w=window.innerWidth,e&&e.meta&&(i.m=JSON.stringify(e.meta)),e&&e.props&&(i.p=e.props);var a=l.getAttributeNames().filter(function(t){return"event-"===t.substring(0,6)}),n=i.p||{};a.forEach(function(t){var e=t.replace("event-",""),i=l.getAttribute(t);n[e]=n[e]||i}),i.p=n;var r=new XMLHttpRequest;r.open("POST",p,!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(i)),r.onreadystatechange=function(){4===r.readyState&&e&&e.callback&&e.callback()}}}function n(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!==o.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(){o.href=e.href},150),t.preventDefault()))}s.addEventListener("click",n),s.addEventListener("auxclick",n);var r=window.plausible&&window.plausible.q||[];window.plausible=a;for(var u,c=0;c<r.length;c++)a.apply(this,r[c]);function d(){u!==o.pathname&&(u=o.pathname,a("pageview"))}var w,f=window.history;f.pushState&&(w=f.pushState,f.pushState=function(){w.apply(this,arguments),d()},window.addEventListener("popstate",d)),"prerender"===s.visibilityState?s.addEventListener("visibilitychange",function(){u||"visible"!==s.visibilityState||d()}):d()}();