Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
function normalizePathname(pathname?: string) {
if (!pathname) {
return '';
}
return `/${pathname.replace(/^\/+/, '')}`;
}
function normalizeBasePath(basePath?: string) {
if (!basePath) {
return '';
}
return `/${basePath.replace(/^\/+|\/+$/g, '')}`;
}
export function matchesConfiguredPath(
pathname: string,
configuredPath?: string,
basePath?: string,
) {
const normalizedPathname = normalizePathname(pathname);
const normalizedConfiguredPath = normalizePathname(configuredPath);
if (!normalizedConfiguredPath) {
return false;
}
if (normalizedPathname === normalizedConfiguredPath) {
return true;
}
const normalizedBasePath = normalizeBasePath(basePath);
return normalizedBasePath
? normalizedPathname === `${normalizedBasePath}${normalizedConfiguredPath}`
: false;
}