This package is a wrapper around the PostHog analytics library for the Next.js App Router.
It simplifies posthog setup and enables event tracking.
pnpm install @bob-obringer/posthog-nextjs
npm install @bob-obringer/posthog-nextjs
yarn add @bob-obringer/posthog-nextjs
The package provides a PosthogProvider
component that should be
wrapped around your NextJS application (generally with other providers)
import { type ReactNode } from "react";
import { PosthogProvider } from "@bob-obringer/posthog-nextjs";
import { env } from "@/config/client";
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>
<PosthogProvider token={env.posthog.apiKey} host={env.posthog.host}>
{children}
</PosthogProvider>
</body>
</html>
);
}
This is very crude for now. It just removes some setup boilerplate for new projects.