@bentonow/bento-nextjs-sdk

中文文档
0.0.1-rc3发布于 2024/12/28MITTypeScriptESM + CJS零依赖近 30 天下载 2288

🍱 Bento Next.JS SDK and tracking library

原始使用文档
文档目录11 节
  1. Features
  2. Requirements
  3. Getting started
  4. Installation
  5. Configuration
  6. Modules
  7. Page View Tracking
  8. Custom Event Tracking
  9. Things to Know
  10. Contributing
  11. License

Bento Next.js SDK

[!TIP] Need help? Join our Discord or email [email protected] for personalized support.

The Bento Next.js SDK makes it quick and easy to build an excellent analytics experience in your Next.js application. We provide powerful and customizable components and hooks that can be used out-of-the-box to track your users' behavior and manage analytics. We also expose low-level APIs so that you can build fully custom experiences.

Get started with our 📚 integration guides, or 📘 browse the SDK reference.

Table of contents

Features

  • Easy integration: Quickly add Bento analytics to your Next.js application with pre-built components.
  • Page view tracking: Automatically track page views across your Next.js application.
  • User identification: Easily identify users for more detailed analytics.
  • Custom event tracking: Track custom events both on the client-side and server-side.
  • Next.js version support: Compatible with both Next.js 13+ and legacy versions.
  • Server-side integration: Optional server-side tracking with the Bento Node SDK.

Requirements

  • Next.js 12.0+ (with specific support for 13+)
  • Node.js 14+
  • Bento Account for a valid SITE_UUID

Getting started

Installation

Install the Bento Next.js SDK:

npm install @bentonow/bento-nextjs-sdk --save

Optionally, install the Bento Node SDK for server-side integration:

npm install @bentonow/bento-node-sdk --save

Configuration

Add the Bento analytics component to your top-level layout:

For Next.js 13+:

import { BentoAnalytics } from '@bentonow/bento-nextjs-sdk/analytics'

export default function Layout({ children }) {
  return (
    <html>
      <body>
        <BentoAnalytics siteUuid={process.env.NEXT_PUBLIC_BENTO_SITE_ID!} userEmail={''} />
        {children}
      </body>
    </html>
  )
}

For Next.js 12 (legacy):

import { BentoLegacyAnalytics } from '@bentonow/bento-nextjs-sdk/analytics/legacy'

function MyApp({ Component, pageProps }) {
  return (
    <>
      <BentoLegacyAnalytics siteUuid={process.env.NEXT_PUBLIC_BENTO_SITE_ID!} userEmail={''} />
      <Component {...pageProps} />
    </>
  )
}

Modules

Page View Tracking

Automatically track page views:

// Next.js 13+
import { useBentoAnalytics } from '@bentonow/bento-nextjs-sdk/analytics'

export default function Layout({ children }) {
  useBentoAnalytics(userEmail)
  return <>{children}</>
}

// Next.js 12 (legacy)
import { useBentoLegacyAnalytics } from '@bentonow/bento-nextjs-sdk/analytics/legacy'

function MyApp({ Component, pageProps }) {
  useBentoLegacyAnalytics(userEmail)
  return <Component {...pageProps} />
}

Custom Event Tracking

Track custom events on the client-side:

window.bento.track('optin', { organisation_name: 'Team Rocket' })
window.bento.tag('customer')

Track custom events on the server-side:

import { Analytics } from '@bentonow/bento-node-sdk'

const bento = new Analytics({ /* your configuration */ })

await bento.V1.track({
  email: '[email protected]',
  type: 'optin',
  fields: {
    organisation_name: 'Team Rocket'
  }
})

Things to Know

  1. The SDK provides different components for Next.js 13+ and legacy versions.
  2. Page view tracking is automatic when using the provided components and hooks.
  3. User identification can be done by passing the user's email to the analytics components or hooks.
  4. The SDK supports both client-side and server-side event tracking.
  5. For more advanced usage, you can customize the integration using the Next.js Script component.

Contributing

We welcome contributions! Please see our contributing guidelines for details on how to submit pull requests, report issues, and suggest improvements.

License

The Bento SDK for Next.js is available as open source under the terms of the MIT License.

版本与发布记录

@bentonow/bento-nextjs-sdk 共发布 3 个版本,首次发布于 2024/06/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.1-rc3latest2024/12/281.9 年前
0.0.1-rc22024/06/042 年前
0.0.1-rc12024/06/042 年前

关于 @bentonow/bento-nextjs-sdk 的常见问题

@bentonow/bento-nextjs-sdk 是什么?

🍱 Bento Next.JS SDK and tracking library

如何安装 @bentonow/bento-nextjs-sdk?

在项目目录运行 npm install @bentonow/bento-nextjs-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(^12.0.0 || ^13.0.0 || ^14.0.0 || >=15.0.0-rc)、react(^17.0.0 || ^18.0.0 || >=19.0.0-beta)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bentonow/bento-nextjs-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bentonow/bento-nextjs-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bentonow/bento-nextjs-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.17.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bentonow/bento-nextjs-sdk 可以商用吗?

@bentonow/bento-nextjs-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bentonow/bento-nextjs-sdk 的下载量有多少?

根据 npm 官方下载统计,@bentonow/bento-nextjs-sdk 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,288 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bentonow/bento-nextjs-sdk 还在维护吗?

最新版本 0.0.1-rc3 发布于 2024/12/28(1.9 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/06/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。