Skip to content

armgit / umami

Public Imported from GitHub
0

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.

Handle domain name in share URL path

Mike Cao4e8be724ac44
diff --git a/src/app/share/ShareProvider.tsx b/src/app/share/ShareProvider.tsx
index 9862a9742..b83d37949 100644
--- a/src/app/share/ShareProvider.tsx
+++ b/src/app/share/ShareProvider.tsx
@@ -32,11 +32,23 @@ const ALL_SECTION_IDS = [
'attribution',
];
+function getSharePath(pathname: string) {
+ const segments = pathname.split('/');
+ const firstSegment = segments[3];
+
+ // If first segment looks like a domain name, skip it
+ if (firstSegment?.includes('.')) {
+ return segments[4];
+ }
+
+ return firstSegment;
+}
+
export function ShareProvider({ slug, children }: { slug: string; children: ReactNode }) {
const { share, isLoading, isFetching } = useShareTokenQuery(slug);
const router = useRouter();
const pathname = usePathname();
- const path = pathname.split('/')[3];
+ const path = getSharePath(pathname);
const allowedSections = share?.parameters
? ALL_SECTION_IDS.filter(id => share.parameters[id] !== false)
diff --git a/src/app/share/[slug]/[[...path]]/SharePage.tsx b/src/app/share/[slug]/[[...path]]/SharePage.tsx
index 5d93fd962..d80bc3b15 100644
--- a/src/app/share/[slug]/[[...path]]/SharePage.tsx
+++ b/src/app/share/[slug]/[[...path]]/SharePage.tsx
@@ -39,11 +39,23 @@ const PAGE_COMPONENTS: Record<string, React.ComponentType<{ websiteId: string }>
attribution: AttributionPage,
};
+function getSharePath(pathname: string) {
+ const segments = pathname.split('/');
+ const firstSegment = segments[3];
+
+ // If first segment looks like a domain name, skip it
+ if (firstSegment?.includes('.')) {
+ return segments[4];
+ }
+
+ return firstSegment;
+}
+
export function SharePage() {
const share = useShare();
const { setTheme } = useTheme();
const pathname = usePathname();
- const path = pathname.split('/')[3];
+ const path = getSharePath(pathname);
const { websiteId, parameters = {} } = share;
useEffect(() => {