Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Exclude loopback addresses from analytics (#55)

Marshall Bowersbed7cc1ec711
diff --git a/assets/js/p.js b/assets/js/p.js
index c0a307eb2e..201d3817db 100644
--- a/assets/js/p.js
+++ b/assets/js/p.js
@@ -57,7 +57,7 @@
}
function trigger(eventName, options) {
- if (/localhost$/.test(window.location.hostname)) return ignore('website is running locally');
+ if (/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(window.location.hostname)) return ignore('website is running locally');
if (window.location.protocol === 'file:') return ignore('website is running locally');
if (window.document.visibilityState === 'prerender') return ignore('document is prerendering');
diff --git a/assets/js/plausible.js b/assets/js/plausible.js
index d7c9ef9fdb..af031e150e 100644
--- a/assets/js/plausible.js
+++ b/assets/js/plausible.js
@@ -62,7 +62,7 @@
}
function trigger(eventName, options) {
- if (/localhost$/.test(window.location.hostname)) return ignore('website is running locally');
+ if (/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(window.location.hostname)) return ignore('website is running locally');
if (window.location.protocol === 'file:') return ignore('website is running locally');
if (window.document.visibilityState === 'prerender') return ignore('document is prerendering');