Next Fathom is a component wrapper
around fathom-client that allows you to quickly
and easily add Fathom Analytics to your Next.js
projects that use the App Router.
To install the package using npm, run the following command in your terminal:
npm install next-fathomAlternatively, if you are using yarn, use the following command:
yarn add next-fathomIn your layout, import and add the Fathom component, and add your Site ID to the siteId prop.
This will load the Fathom client and track page views automatically.
import { Fathom } from "next-fathom";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<Fathom
siteId={"MY_FATHOM_ID"}
options={{ includedDomains: ["example.com"] }}
/>
{children}
</body>
</html>
);
}This package also re-exports everything from
the fathom-client package
(e.g. trackGoal).
See
the fathom-client readme
for how to use these.
If you’ve not yet signed up you can use my referral link to get $10 credit.