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

1 line
1.7 KiB
JavaScript
Raw Normal View History

!function(){"use strict";var t,e,n,o=window.location,l=window.document,s=l.getElementById("plausible"),c=s.getAttribute("data-api")||(t=s.src.split("/"),e=t[0],n=t[2],e+"//"+n+"/api/event");function u(t){console.warn("Ignoring Event: "+t)}function a(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(o.hostname)||"file:"===o.protocol)return u("localhost");if(!(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)){try{if("true"===window.localStorage.plausible_ignore)return u("localStorage flag")}catch(t){}var n={};n.n=t,n.u=e&&e.u?e.u:o.href,n.d=s.getAttribute("data-domain"),n.r=l.referrer||null,n.w=window.innerWidth,e&&e.meta&&(n.m=JSON.stringify(e.meta)),e&&e.props&&(n.p=e.props);var a=s.getAttributeNames().filter(function(t){return"event-"===t.substring(0,6)}),r=n.p||{};a.forEach(function(t){var e=t.replace("event-",""),n=s.getAttribute(t);r[e]=r[e]||n}),n.p=r;var i=new XMLHttpRequest;i.open("POST",c,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(n)),i.onreadystatechange=function(){4===i.readyState&&e&&e.callback&&e.callback()}}}function r(t){for(var e=t.target,n="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&&((n||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()))}l.addEventListener("click",r),l.addEventListener("auxclick",r);var i=window.plausible&&window.plausible.q||[];window.plausible=a;for(var p=0;p<i.length;p++)a.apply(this,i[p])}();