@1mn/react

中文文档
0.4.0发布于 2026/07/06MITTypeScriptESM + CJS零依赖近 30 天下载 2.6万

React bindings for the 1mn SDK — embedded product analytics, session replay, error tracking, user management, and customer feedback (PostHog/Sentry-like). Self-contained: npm install + , no snippet.

原始使用文档
文档目录14 节
  1. Install
  2. Quickstart
  3. Custom events
  4. Customer feedback
  5. Next.js (App Router)
  6. React Router 7 / Remix / TanStack Start (SSR)
  7. API
  8. <OnemnProvider apiKey host? user? >
  9. useOnemn()
  10. <FeedbackWidget />
  11. useFeedback()
  12. getOnemn()
  13. Privacy
  14. License

@1mn/react

React bindings for the 1mn SDK — embedded product analytics, error tracking, and user management (PostHog/Sentry-like) for your React or Next.js app.

Self-contained: it bundles the SDK core, so npm install + one provider is all you need. No snippet, no script tag.

  • 📈 Analytics — automatic pageviews (incl. SPA navigations), sessions, web vitals, and custom events.
  • 👥 User management — identify your signed-in users (with email) and watch them in your 1mn dashboard.
  • 🐛 Errors — uncaught exceptions and unhandled rejections captured and grouped automatically.
  • 💬 Feedback — a drop-in <FeedbackWidget> (or headless hook) that files customer feedback as tickets.
  • 🎬 Session replay — opt-in per key from your dashboard; the recorder (rrweb) lazy-loads only for sampled sessions, so it never touches this bundle's size. Off by default; inputs masked.
  • 🪶 ~9 KB, zero runtime dependencies, SSR-safe.

Install

npm install @1mn/react

Quickstart

Wrap your app once with OnemnProvider and pass your public key (1mn_pk_…, from the Users tab in your 1mn dashboard) plus your signed-in user:

import { OnemnProvider } from "@1mn/react";

export default function App({ children, user }) {
  return (
    <OnemnProvider apiKey="1mn_pk_xxx" user={user}>
      {children}
    </OnemnProvider>
  );
}

That's it — pageviews, web vitals, and errors are captured automatically, and user is identified (with email/name) whenever it's set. When user becomes null (logout) the SDK resets.

Custom events

import { useOnemn } from "@1mn/react";

function CheckoutButton() {
  const onemn = useOnemn();
  return (
    <button onClick={() => onemn.capture("checkout_started", { plan: "pro" })}>
      Upgrade
    </button>
  );
}

Customer feedback

Collect in-app feedback with one component. Drop in the widget for a floating launcher + modal:

import { FeedbackWidget } from "@1mn/react";

<FeedbackWidget />;

Or drive the modal from your own button (no launcher):

import { useState } from "react";
import { FeedbackWidget } from "@1mn/react";

function Sidebar() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <button onClick={() => setOpen(true)}>Feedback</button>
      <FeedbackWidget launcher={false} open={open} onOpenChange={setOpen} />
    </>
  );
}

Prefer your own UI? Use the headless hook (or useOnemn().feedback):

import { useFeedback } from "@1mn/react";

const { send } = useFeedback();
send("Love the new dashboard!");

Each submission emits a $feedback event. In your 1mn dashboard these are filed as feedback tickets in your backlog for triage — they never trigger an autonomous agent run on their own.

Next.js (App Router)

OnemnProvider is a client component — render it in a "use client" boundary (e.g. a providers.tsx wrapped around children in your root layout). It's SSR-safe: nothing runs until the browser hydrates. <FeedbackWidget> is likewise a client component.

React Router 7 / Remix / TanStack Start (SSR)

OnemnProvider is SSR-safe — render it from a normal module in your root route (e.g. app/root.tsx), wrapped around your <Outlet />:

// app/root.tsx — a normal module, NOT a *.client.tsx file
import { OnemnProvider } from "@1mn/react";
import { useSession } from "./lib/auth-client";

export default function App() {
  const { data: session } = useSession();
  return (
    <OnemnProvider apiKey="1mn_pk_xxx" user={session?.user}>
      <Outlet />
    </OnemnProvider>
  );
}

⚠️ Do not put OnemnProvider (or a wrapper around it) in a *.client.tsx file and render that in the SSR tree. React Router 7, Remix and Vite empty *.client.* modules in the server build, so the import is undefined during SSR and React throws on <undefined> — HTTP 500 on every route. OnemnProvider doesn't need to be client-only; it's already SSR-safe.

If your user/session hook is client-only (it lives in a *.client.* module, or is undefined on the server), keep OnemnProvider SSR-safe and move just the identify call into a small child rendered behind a mounted guard (useOnemn().identify(...) inside a useEffect) — don't make the whole provider client-only. After wiring it in, confirm the site still returns 200, not 500.

API

<OnemnProvider apiKey host? user? >

PropTypeNotes
apiKeystringYour public key (1mn_pk_…). Required.
hoststringIngest origin. Defaults to the 1mn collector.
user{ id, email?, name? } | nullSigned-in user. Identified when it has an email.

useOnemn()

Returns { capture, identify, reset, set, feedback, optOut, optIn }. Stable across renders; SSR-safe (no-ops on the server and before init).

  • capture(event, properties?) — a custom event.
  • identify(id, set?, setOnce?) — usually unnecessary if you pass user to the provider.
  • set(properties) — update person properties without re-identifying.
  • feedback(message, properties?) — send an in-app feedback/support message.
  • reset() — clear identity (logout); the provider does this for you when user clears.
  • optOut() / optIn() — stop / resume sending.

<FeedbackWidget />

A drop-in feedback launcher + modal. All props optional:

PropTypeNotes
launcherbooleanShow the floating launcher button. Default true.
openbooleanControlled open state. Omit for uncontrolled.
onOpenChange(open: boolean) => voidOpen/close callback.
labelstringLauncher text. Default "Feedback".
titlestringModal heading. Default "Send feedback".
descriptionstringSub-text under the heading.
placeholderstringTextarea placeholder.
position"bottom-right" | "bottom-left"Launcher corner. Default "bottom-right".
accentColorstringPrimary button / launcher color.
propertiesRecord<string, unknown>Extra props merged into the $feedback event.
onSubmit(message: string) => voidCalled after a successful send.

useFeedback()

Returns { send(message, properties?) } for building your own feedback UI.

getOnemn()

The live client (or null on the server / before init), for non-component code.

Privacy

By default the SDK captures no DOM content (no autocapture) and no IP-derived geo, and ships optOut(). Session replay is the one exception and is off unless you enable it for your key in the 1mn dashboard: when on, it records the DOM/interactions of a sampled fraction of sessions via rrweb, with text inputs masked by default (add onemn-block / onemn-mask classes to hide regions). optOut() also stops recording. You are the data controller for your end-users' data — if you enable replay, tell your visitors (EU/UK/CA consent).

License

MIT — see LICENSE.

版本与发布记录

@1mn/react 共发布 4 个版本,首次发布于 2026/06/12;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.4.0latest2026/07/064 个月前
0.3.02026/06/164 个月前
0.2.02026/06/144 个月前
0.1.02026/06/124 个月前

关于 @1mn/react 的常见问题

@1mn/react 是什么?

React bindings for the 1mn SDK — embedded product analytics, session replay, error tracking, user management, and customer feedback (PostHog/Sentry-like). Self-contained: npm install + , no snippet.

如何安装 @1mn/react?

在项目目录运行 npm install @1mn/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=17.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@1mn/react 支持 TypeScript 吗?

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

@1mn/react 支持 ESM 还是 CommonJS?

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

@1mn/react 可以商用吗?

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

@1mn/react 的下载量有多少?

根据 npm 官方下载统计,@1mn/react 在 2026/10/05 – 2026/11/03 这 30 天内被下载 25,531 次,日均约 851 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@1mn/react 还在维护吗?

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