From 4ab71c42a6a36c4a455a54236e56e7b7fbb5843c Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Tue, 15 Sep 2020 21:25:51 -0700 Subject: [PATCH] Update display of combined referrer urls. --- components/metrics/ReferrersTable.js | 6 +++--- lib/filters.js | 11 ++++++++--- lib/lang.js | 2 +- lib/url.js | 4 ++++ package.json | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/components/metrics/ReferrersTable.js b/components/metrics/ReferrersTable.js index 85834212..0527c68a 100644 --- a/components/metrics/ReferrersTable.js +++ b/components/metrics/ReferrersTable.js @@ -20,9 +20,9 @@ export default function ReferrersTable({ websiteId, websiteDomain, limit, onExpa { label: , value: FILTER_RAW }, ]; - const renderLink = ({ x: url }) => { - return url.startsWith('http') ? ( - + const renderLink = ({ w: href, x: url }) => { + return (href || url).startsWith('http') ? ( + {decodeURI(url)} ) : ( diff --git a/lib/filters.js b/lib/filters.js index e4d9e48c..ee0a1759 100644 --- a/lib/filters.js +++ b/lib/filters.js @@ -1,6 +1,6 @@ import firstBy from 'thenby'; import { BROWSERS, ISO_COUNTRIES } from './constants'; -import { removeTrailingSlash, getDomainName } from './url'; +import { removeTrailingSlash, removeWWW, getDomainName } from './url'; export const urlFilter = (data, { raw }) => { const isValidUrl = url => { @@ -55,6 +55,7 @@ export const urlFilter = (data, { raw }) => { export const refFilter = (data, { domain, domainOnly, raw }) => { const domainName = getDomainName(domain); const regex = new RegExp(`http[s]?://${domainName}`); + const links = {}; const isValidRef = ref => { return ref !== '' && !ref.startsWith('/') && !ref.startsWith('#'); @@ -85,7 +86,7 @@ export const refFilter = (data, { domain, domainOnly, raw }) => { const ref = searchParams.get('ref'); const query = ref ? `?ref=${ref}` : ''; - return `${origin}${path}${query}`; + return removeTrailingSlash(`${removeWWW(hostname)}${path}`) + query; } return null; @@ -101,6 +102,10 @@ export const refFilter = (data, { domain, domainOnly, raw }) => { const url = cleanUrl(x); + if (!domainOnly && !raw) { + links[url] = x; + } + if (url) { if (!obj[url]) { obj[url] = y; @@ -113,7 +118,7 @@ export const refFilter = (data, { domain, domainOnly, raw }) => { }, {}); return Object.keys(map) - .map(key => ({ x: key, y: map[key] })) + .map(key => ({ x: key, y: map[key], w: links[key] })) .sort(firstBy('y', -1).thenBy('x')); }; diff --git a/lib/lang.js b/lib/lang.js index d45d7ce0..8568ed4f 100644 --- a/lib/lang.js +++ b/lib/lang.js @@ -38,7 +38,7 @@ export const dateLocales = { }; export const menuOptions = [ - { label: 'English', value: 'en', display: 'EN' }, + { label: 'English', value: 'en-US', display: 'EN' }, { label: '中文', value: 'zh-CN', display: 'CN' }, { label: 'Deutsch', value: 'de-DE', display: 'DE' }, { label: 'Español', value: 'es-MX', display: 'ES' }, diff --git a/lib/url.js b/lib/url.js index 0eb4a04a..d90c390e 100644 --- a/lib/url.js +++ b/lib/url.js @@ -2,6 +2,10 @@ export function removeTrailingSlash(url) { return url && url.length > 1 && url.endsWith('/') ? url.slice(0, -1) : url; } +export function removeWWW(url) { + return url && url.length > 1 && url.startsWith('www.') ? url.slice(4) : url; +} + export function getDomainName(str) { try { return new URL(str).hostname; diff --git a/package.json b/package.json index 635fe153..65726297 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "umami", - "version": "0.35.0", + "version": "0.36.0", "description": "A simple, fast, website analytics alternative to Google Analytics. ", "author": "Mike Cao ", "license": "MIT",