format:fix

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-13 08:55:24 +01:00
parent 558318c312
commit 48aecc4b37
117 changed files with 4455 additions and 667 deletions

View File

@@ -1,41 +1,41 @@
import { stripTrailingSlash } from "@openpanel/common";
import { stripTrailingSlash } from '@openpanel/common';
import referrers from "../referrers";
import referrers from '../referrers';
function getHostname(url: string | undefined) {
if (!url) {
return "";
return '';
}
try {
return new URL(url).hostname;
} catch (e) {
return "";
return '';
}
}
export function parseReferrer(url: string | undefined) {
const hostname = getHostname(url);
const match = referrers[hostname] ?? referrers[hostname.replace("www.", "")];
const match = referrers[hostname] ?? referrers[hostname.replace('www.', '')];
return {
name: match?.name ?? "",
type: match?.type ?? "unknown",
url: stripTrailingSlash(url ?? ""),
name: match?.name ?? '',
type: match?.type ?? 'unknown',
url: stripTrailingSlash(url ?? ''),
};
}
export function getReferrerWithQuery(
query: Record<string, string> | undefined,
query: Record<string, string> | undefined
) {
if (!query) {
return null;
}
const source = query.utm_source ?? query.ref ?? query.utm_referrer ?? "";
const source = query.utm_source ?? query.ref ?? query.utm_referrer ?? '';
const match = Object.values(referrers).find(
(referrer) => referrer.name.toLowerCase() === source?.toLowerCase(),
(referrer) => referrer.name.toLowerCase() === source?.toLowerCase()
);
if (!match) {
@@ -45,6 +45,6 @@ export function getReferrerWithQuery(
return {
name: match.name,
type: match.type,
url: "",
url: '',
};
}