analytics/priv/tracker/js/plausible.hash.js
Vignesh Joglekar fb7a3fef89
Adds data-exclude support and localStorage.plausible_ignore support (#489)
* Adds data-exclude support and plausible_ignore support

* Splits exclusion into separate script option

* localStorage parsing upgrades

* Additional script type additions

I'm unsure about the formatting decision in tracker.ex - lmk.

* Adds new compiled files

This will certainly have conflicts with my other PRs related to the tracking scripts right now, I'll make one extra PR after both are done to ensure they're consolidated into the compiled scripts.

* Moves localStorage blocker out of special script

* Changelog

* Second thoughts on localStorage exclusion

* Updates `*` to not match `/` or whitespace

* Fix formatting

* Removes zero-length asterisks

* Adds support for double glob, zero-length replacements

* Update to reduce size+allow localStorage exclude

Co-authored-by: Uku Taht <Uku.taht@gmail.com>
2021-01-22 13:32:40 +02:00

1 line
1.2 KiB
JavaScript

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