Skip to content

Commit

Permalink
Exclude analytics from examples page (#1376)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SutuSebastian committed Apr 23, 2024
1 parent 7ddef82 commit 2afa3c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
15 changes: 5 additions & 10 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ThemeModeScript } from "flowbite-react";
import { Inter as InterFont } from "next/font/google";
import type { Metadata, NextPage, Viewport } from "next/types";
import type { FC, PropsWithChildren } from "react";
import type { Metadata, Viewport } from "next/types";
import type { PropsWithChildren } from "react";
import { FathomScript } from "~/components/fathom-script";

import "~/styles/globals.css";

Expand Down Expand Up @@ -53,7 +54,7 @@ export const viewport: Viewport = {
],
};

const RootLayout: NextPage<PropsWithChildren> = ({ children }) => {
export default function RootLayout({ children }: PropsWithChildren) {
return (
<html lang="en" className={`${interFont.variable} font-sans`}>
<head>
Expand All @@ -65,10 +66,4 @@ const RootLayout: NextPage<PropsWithChildren> = ({ children }) => {
</body>
</html>
);
};

const FathomScript: FC = () => {
return <script data-site="UXMSXUQI" defer src="https://cdn.usefathom.com/script.js" />;
};

export default RootLayout;
}
12 changes: 12 additions & 0 deletions apps/web/components/fathom-script.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use client";

import { usePathname } from "next/navigation";

export function FathomScript() {
const pathname = usePathname();
const isExamplesPage = pathname.startsWith("/examples/");

if (isExamplesPage) return null;

return <script data-site="UXMSXUQI" defer src="https://cdn.usefathom.com/script.js" />;
}

0 comments on commit 2afa3c8

Please sign in to comment.