api: improve ref parser

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-14 09:50:23 +01:00
parent 1c3bd0ea2e
commit 7300631630
2 changed files with 17 additions and 9 deletions

View File

@@ -34,17 +34,25 @@ export function getReferrerWithQuery(
const source = query.utm_source ?? query.ref ?? query.utm_referrer ?? '';
const match = Object.values(referrers).find(
(referrer) => referrer.name.toLowerCase() === source?.toLowerCase()
);
if (!match) {
if (source === '') {
return null;
}
const match = Object.values(referrers).find(
(referrer) => referrer.name.toLowerCase() === source.toLowerCase()
);
if (match) {
return {
name: match.name,
type: match.type,
url: '',
};
}
return {
name: match.name,
type: match.type,
name: source,
type: 'unknown',
url: '',
};
}