Agent setup: authorize Sight MCP and ask your agent to call get_tracking_setup. It configures this integration automatically.

Next.js

Sight analytics for Next.js App Router. Thin wrapper around @sightapp/analytics — same init/track API, packaged as a client component for the App Router.

Install

npm install @sightapp/nextjs

@sightapp/analytics isn't published to npm yet — until it ships, point your lockfile at the local checkout instead:

npm install file:../sight-js

(both repos as sibling checkouts, e.g. under the same parent directory).

Usage

Drop into your root layout, inside <body>:

// app/layout.tsx
import { SightAnalytics } from "@sightapp/nextjs";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <SightAnalytics apiKey="pk_your_project_api_key" />
        {children}
      </body>
    </html>
  );
}

Custom events, anywhere:

import { track } from "@sightapp/nextjs";
track("signup");

How SPA navigation is tracked — and a documented assumption

@sightapp/analytics's init() patches history.pushState and fires a pageview on every call. Next.js's client-side navigation (router.push, <Link>) routes through the native History API under the hood for both Pages and App Router, so that patch picks up client-side navigations without any extra wiring here.

This package deliberately does not also track pageviews via usePathname/useSearchParams (the pattern Next's own docs show for third-party analytics) — doing both would double-count every navigation, since the init() patch already fires on each one.

Assumption not independently re-verified this session: that Next.js continues to route client-side navigation through history.pushState/replaceState. This has held since client-side transitions were introduced and is unlikely to change, but if a future Next.js version moves off the History API for navigation, SPA pageviews would silently stop firing and this package would need to switch to an explicit usePathname/useSearchParams-based tracker instead. Worth a quick check against current Next.js internals/docs before depending on this for a production analytics number you care about.

Build

npm run build       # tsup: emits dist/{index.js,index.cjs,index.d.ts}
npm run typecheck

Source repository