analytics/priv/tracker/js/plausible.compat.dimensions.exclusions.hash.js
RobertJoonas 11654ddc07
Script extension additions (#1915)
* added data-include attribute to plausible.exclusions.js

* reorder extensions in filename when serving the plausible script

* fix formatting

* tweaks after review

* changelog update
2022-05-27 10:11:40 +03:00

1 line
1.7 KiB
JavaScript

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