@bob-obringer/nextjs-posthog
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

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>
  );
}

Package Sidebar

Install

npm i @bob-obringer/nextjs-posthog

Weekly Downloads

1

Version

0.4.0

License

MIT

Unpacked Size

80.7 kB

Total Files

13

Last publish

Collaborators

  • bob-obringer