Skip to content

Commit 2afa3c8

Browse files
Exclude analytics from examples page (#1376)
* fix: exclude analytics from `examples` page leading to page-load-count inception due to code preview examples iframe * chore: isolate fathom-script into client component + fix reliability of the pathname
1 parent 7ddef82 commit 2afa3c8

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

apps/web/app/layout.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ThemeModeScript } from "flowbite-react";
22
import { Inter as InterFont } from "next/font/google";
3-
import type { Metadata, NextPage, Viewport } from "next/types";
4-
import type { FC, PropsWithChildren } from "react";
3+
import type { Metadata, Viewport } from "next/types";
4+
import type { PropsWithChildren } from "react";
5+
import { FathomScript } from "~/components/fathom-script";
56

67
import "~/styles/globals.css";
78

@@ -53,7 +54,7 @@ export const viewport: Viewport = {
5354
],
5455
};
5556

56-
const RootLayout: NextPage<PropsWithChildren> = ({ children }) => {
57+
export default function RootLayout({ children }: PropsWithChildren) {
5758
return (
5859
<html lang="en" className={`${interFont.variable} font-sans`}>
5960
<head>
@@ -65,10 +66,4 @@ const RootLayout: NextPage<PropsWithChildren> = ({ children }) => {
6566
</body>
6667
</html>
6768
);
68-
};
69-
70-
const FathomScript: FC = () => {
71-
return <script data-site="UXMSXUQI" defer src="https://cdn.usefathom.com/script.js" />;
72-
};
73-
74-
export default RootLayout;
69+
}

apps/web/components/fathom-script.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use client";
2+
3+
import { usePathname } from "next/navigation";
4+
5+
export function FathomScript() {
6+
const pathname = usePathname();
7+
const isExamplesPage = pathname.startsWith("/examples/");
8+
9+
if (isExamplesPage) return null;
10+
11+
return <script data-site="UXMSXUQI" defer src="https://cdn.usefathom.com/script.js" />;
12+
}

0 commit comments

Comments
 (0)