From 5120805e0b44a3708b237ceaf9222a68ef95c039 Mon Sep 17 00:00:00 2001 From: Harry Oosterveen Date: Wed, 12 Mar 2025 20:44:29 +0100 Subject: [PATCH] Fix counting _other domain groups --- src/components/metrics/ReferrersTable.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/metrics/ReferrersTable.tsx b/src/components/metrics/ReferrersTable.tsx index 4d5a87c3..89729418 100644 --- a/src/components/metrics/ReferrersTable.tsx +++ b/src/components/metrics/ReferrersTable.tsx @@ -60,19 +60,24 @@ export function ReferrersTable({ allowFilter, ...props }: ReferrersTableProps) { ); }; + const getDomain = (x: string) => { + for (const { domain, match } of GROUPED_DOMAINS) { + if (Array.isArray(match) ? match.some(str => x.includes(str)) : x.includes(match)) { + return domain; + } + } + return '_other'; + }; + const groupedFilter = (data: any[]) => { const groups = { _other: 0 }; for (const { x, y } of data) { - for (const { domain, match } of GROUPED_DOMAINS) { - if (Array.isArray(match) ? match.some(str => x.includes(str)) : x.includes(match)) { - if (!groups[domain]) { - groups[domain] = 0; - } - groups[domain] += +y; - } + const domain = getDomain(x); + if (!groups[domain]) { + groups[domain] = 0; } - groups._other += +y; + groups[domain] += +y; } return Object.keys(groups)