analytics/priv/tracker/js/plausible.dimensions.local.manual.outbound-links.js
RobertJoonas 199206babc
Dimensions continued (#1847)
* added the first version of dimensions extension

* finished dimensions script extension + updated tracking to use it

* script variants build
2022-04-25 10:56:11 +03:00

1 line
1.5 KiB
JavaScript

!function(){"use strict";var o=window.location,c=window.document,l=c.currentScript,u=l.getAttribute("data-api")||new URL(l.src).origin+"/api/event";function e(e,t){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(e){}var r={};r.n=e,r.u=t&&t.u?t.u:o.href,r.d=l.getAttribute("data-domain"),r.r=c.referrer||null,r.w=window.innerWidth,t&&t.meta&&(r.m=JSON.stringify(t.meta)),t&&t.props&&(r.p=t.props);var n=l.getAttributeNames().filter(function(e){return"event-"===e.substring(0,6)}),a=r.p||{};n.forEach(function(e){var t=e.replace("event-",""),r=l.getAttribute(e);a[t]=a[t]||r}),r.p=a;var i=new XMLHttpRequest;i.open("POST",u,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(r)),i.onreadystatechange=function(){4===i.readyState&&t&&t.callback&&t.callback()}}}function t(e){for(var t=e.target,r="auxclick"===e.type&&2===e.which,n="click"===e.type;t&&(void 0===t.tagName||"a"!==t.tagName.toLowerCase()||!t.href);)t=t.parentNode;t&&t.href&&t.host&&t.host!==o.host&&((r||n)&&plausible("Outbound Link: Click",{props:{url:t.href}}),t.target&&!t.target.match(/^_(self|parent|top)$/i)||e.ctrlKey||e.metaKey||e.shiftKey||!n||(setTimeout(function(){o.href=t.href},150),e.preventDefault()))}c.addEventListener("click",t),c.addEventListener("auxclick",t);var r=window.plausible&&window.plausible.q||[];window.plausible=e;for(var n=0;n<r.length;n++)e.apply(this,r[n])}();