Connect Next.js to Bento.

Track page views and events in your Next.js app, and handle server-side tracking with the Bento Node.js SDK.

Next.jsBento
Next.js to Bento
  • Page views

    dana@example.com

    Recordednow
  • Server-side events and subscribers

    sam@example.com

    Recorded2s ago
  • window.bento.tag(tag)

    omar@example.com

    Recorded5s ago
  • window.bento.track(event, data)

    priya@example.com

    Recorded7s ago
Listening for Next.js data

Built by

Bento

Type

SDK

Category

Developer

Setup

4 steps

How it works.

The Next.js SDK adds the Bento script to your layout and sends a page view on every route change. In the browser you identify users, track events, and add tags with window.bento.

For server-side events and subscriber management, you pair it with the Node.js SDK in API routes or server actions.

Set it up in four steps.

  1. 1

    Install the SDK

    Install the Next.js SDK. Add the Node.js SDK too if you want to track from the server.

    Shell
    npm install @bentonow/bento-nextjs-sdk --save
    npm install @bentonow/bento-node-sdk --save
  2. 2

    Add your keys

    Put your Site UUID and API keys in your environment file. Find the keys under Your Private API Keys on your Bento team page.

    Shell
    NEXT_PUBLIC_BENTO_SITE_ID=your_site_uuid
    BENTO_PUBLISHABLE_KEY=your_publishable_key
    BENTO_SECRET_KEY=your_secret_key
  3. 3

    Add the analytics component

    Render BentoAnalytics in your App Router layout, or BentoLegacyAnalytics from @bentonow/bento-nextjs-sdk/analytics/legacy in pages/_app. Both load the Bento script with the Site UUID you pass.

    TypeScript
    import { BentoAnalytics } from '@bentonow/bento-nextjs-sdk/analytics'
    
    <BentoAnalytics
      siteUuid={process.env.NEXT_PUBLIC_BENTO_SITE_ID!}
      userEmail=""
    />
  4. 4

    Identify signed-in users

    Pass the signed-in user's email to the optional userEmail prop. The component calls identify before each page view. When they log out, call window.bento.identify('') to clear the stored email.

    TypeScript
    <BentoAnalytics
      siteUuid={process.env.NEXT_PUBLIC_BENTO_SITE_ID!}
      userEmail={user?.email || ''}
    />

What syncs.

  • Page viewsInto Bento

    Sent when the script loads and on every route change. The App Router watches the pathname. The Pages Router listens for routeChangeComplete.

  • window.bento.identify(email)Into Bento

    Links the visitor to a user email. The component calls it for you when userEmail is set.

  • window.bento.track(event, data)Into Bento

    Records a custom event from the browser.

  • window.bento.tag(tag)Into Bento

    Adds a tag to the current user.

  • Server-side events and subscribersInto Bento

    Sent from API routes or server actions with the Node.js SDK.

Track signup and purchase events.

TypeScript
const handleSignup = () => {
  window.bento?.track('signup', {
    source: 'landing_page',
    plan: 'free'
  })
}

const handlePurchase = () => {
  window.bento?.track('purchase', {
    product_id: 'pro_plan',
    amount: 99,
    currency: 'USD'
  })
}

What you can build with Next.js.

The data lands on the person, so segments, tags, and flows can use it right away.

Profiles stay current.

Ddana@example.comSubscribed
Next.jsuserwelcome
Events47
  • Page viewsJust now
  • Server-side events and subscribers2m ago
  • window.bento.tag(tag)1h ago

Flows start when the data arrives.

  • Welcome

    When signup event tracked

    Live
  • Post-purchase

    When purchase event tracked

    Live
  • Segment nurture

    When tag added

    Live
  • Laravel News
  • Examine
  • Less Annoying CRM
  • Geocodio
  • Authority Hacker
  • HeadshotPro
  • QuickMail

More integrations.

Supabase

Developer

Sample Supabase Edge Functions that send a confirmation email through Bento and record a $user_confirmed event when the user verifies.

Python

Developer

Track events, manage subscribers, and send transactional email from your Python app with Bento's Python SDK.

Ruby on Rails

Developer

Track events, manage subscribers, and send transactional email from your Ruby on Rails app with Bento's Ruby SDK.

Questions about Next.js.

Which component should I use?
Use BentoAnalytics for the App Router. It needs Next.js 13 or later. Use BentoLegacyAnalytics for the Pages Router, including Next.js 12.
How do I track events from server components?
Server components cannot call the browser tracking methods. Use server actions with the Node.js SDK, or pass data to a client component that tracks it.
How do I handle logout?
Call window.bento.identify('') with an empty string. An empty userEmail prop only stops the component from calling identify. It does not clear the stored email.
Does the Next.js integration cost extra?
No. The SDKs and the Events API come with your Bento account. Marketing Platform starts at $29/mo for up to 5,000 active users, with a 30-day free trial.

Connect Next.js in your free trial.

Free for 30 days. Move your lists, flows, and templates with help from a human.