Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Filter subdomains in referrers regex test. Closes #632

Mike Cao7530de87d233
diff --git a/lib/filters.js b/lib/filters.js
index af54b965b..e9723b428 100644
--- a/lib/filters.js
+++ b/lib/filters.js
@@ -1,5 +1,5 @@
import { BROWSERS } from './constants';
-import { removeTrailingSlash, removeWWW, getDomainName } from './url';
+import { removeTrailingSlash, removeWWW } from './url';
export const urlFilter = (data, { raw }) => {
const isValidUrl = url => {
@@ -46,23 +46,18 @@ export const urlFilter = (data, { raw }) => {
};
export const refFilter = (data, { domain, domainOnly, raw }) => {
- const domainName = getDomainName(domain);
- const regex = new RegExp(`http[s]?://${domainName}`);
+ const regex = new RegExp(`http[s]?://([a-z0-9-]+\\.)*${domain}`);
const links = {};
const isValidRef = ref => {
return ref !== '' && ref !== null && !ref.startsWith('/') && !ref.startsWith('#');
};
- if (raw) {
- return data.filter(({ x }) => isValidRef(x) && !regex.test(x));
- }
-
const cleanUrl = url => {
try {
const { hostname, origin, pathname, searchParams, protocol } = new URL(url);
- if (hostname === domainName) {
+ if (regex.test(url)) {
return null;
}
@@ -88,6 +83,10 @@ export const refFilter = (data, { domain, domainOnly, raw }) => {
}
};
+ if (raw) {
+ return data.filter(({ x }) => isValidRef(x) && !regex.test(x));
+ }
+
const map = data.reduce((obj, { x, y }) => {
if (!isValidRef(x)) {
return obj;