Profiles stay current.
Ddana@example.comSubscribed
Next.jsuserwelcome
Events47
- Page viewsJust now
- Server-side events and subscribers2m ago
- window.bento.tag(tag)1h ago
- window.bento.track(event, data)Mon
Track page views and events in your Next.js app, and handle server-side tracking with the Bento Node.js SDK.
Built by
Bento
Type
SDK
Category
Developer
Setup
4 steps
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.
Install the Next.js SDK. Add the Node.js SDK too if you want to track from the server.
npm install @bentonow/bento-nextjs-sdk --save
npm install @bentonow/bento-node-sdk --savePut your Site UUID and API keys in your environment file. Find the keys under Your Private API Keys on your Bento team page.
NEXT_PUBLIC_BENTO_SITE_ID=your_site_uuid
BENTO_PUBLISHABLE_KEY=your_publishable_key
BENTO_SECRET_KEY=your_secret_keyRender 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.
import { BentoAnalytics } from '@bentonow/bento-nextjs-sdk/analytics'
<BentoAnalytics
siteUuid={process.env.NEXT_PUBLIC_BENTO_SITE_ID!}
userEmail=""
/>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.
<BentoAnalytics
siteUuid={process.env.NEXT_PUBLIC_BENTO_SITE_ID!}
userEmail={user?.email || ''}
/>Sent when the script loads and on every route change. The App Router watches the pathname. The Pages Router listens for routeChangeComplete.
Links the visitor to a user email. The component calls it for you when userEmail is set.
Records a custom event from the browser.
Adds a tag to the current user.
Sent from API routes or server actions with the Node.js SDK.
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'
})
}The data lands on the person, so segments, tags, and flows can use it right away.
Developer
Sample Supabase Edge Functions that send a confirmation email through Bento and record a $user_confirmed event when the user verifies.
Developer
Track events, manage subscribers, and send transactional email from your Python app with Bento's Python SDK.
Developer
Track events, manage subscribers, and send transactional email from your Ruby on Rails app with Bento's Ruby SDK.
Free for 30 days. Move your lists, flows, and templates with help from a human.