Installation & setup

Next.js and React setup

Use the plain snippet or the tiny npm package, both end at the same 1KB tracker. The package just makes the component ergonomics nicer.

6 min read Updated June 2026 Installation & setup
<script defer src="cdn.bobray.com/b.js">

Option A: the snippet

In Next.js (App Router), add the snippet to app/layout.tsx using next/script:

import Script from "next/script";

<Script
  defer
  data-site="YOUR_SITE_ID"
  src="https://cdn.bobray.com/b.js"
  strategy="afterInteractive"
/>

Option B: the package

npm install @bobray/next

// app/layout.tsx
import { BobRay } from "@bobray/next";

<BobRay siteId="YOUR_SITE_ID" />

The component renders the same deferred script and adds a useBobray() hook exposing track(event, meta) with types.

Tracking goals from components

const { track } = useBobray();

<button onClick={() => track('signup', { plan: 'growth' })}>
  Create account
</button>

Environment tips

Common pitfalls

The mistakes we see most often on this topic, so you can skip them entirely.

Quick reference

Packagenpm i @bobray/next
Component
HookuseBobray().track(name, meta)
PreviewsExclude *.vercel.app
Did this solve it? If not, write to support with your site ID, a real person replies within one business day.