@bob-obringer/nextjs-posthog
v0.4.0
Published
Bob Obringer NextJS Posthog Client
Downloads
15
Maintainers
Readme
NextJS Posthog Wrapper
This package is a wrapper around the Posthog analytics library for the Next.js App Router.
It simplifies posthog setup and enables event tracking.
Installation
pnpm install @bob-obringer/nextjs-posthog
npm install @bob-obringer/nextjs-posthog
yarn add @bob-obringer/nextjs-posthog
Usage
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/nextjs-posthog";
import { env } from "@/config/client";
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>
<PosthogProvider
token={env.posthog.apiKey}
host={env.posthog.host}
enabled={env.posthog.enabled}
capturePageView={true}
capturePageLeave={false}
>
{children}
</PosthogProvider>
</body>
</html>
);
}