Update display of combined referrer urls.

This commit is contained in:
Mike Cao 2020-09-15 21:25:51 -07:00
parent f113d0cb34
commit 4ab71c42a6
5 changed files with 17 additions and 8 deletions

View File

@ -20,9 +20,9 @@ export default function ReferrersTable({ websiteId, websiteDomain, limit, onExpa
{ label: <FormattedMessage id="metrics.filter.raw" defaultMessage="Raw" />, value: FILTER_RAW },
];
const renderLink = ({ x: url }) => {
return url.startsWith('http') ? (
<a href={url} target="_blank" rel="noreferrer">
const renderLink = ({ w: href, x: url }) => {
return (href || url).startsWith('http') ? (
<a href={href || url} target="_blank" rel="noreferrer">
{decodeURI(url)}
</a>
) : (

View File

@ -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'));
};

View File

@ -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' },

View File

@ -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;

View File

@ -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 <mike@mikecao.com>",
"license": "MIT",