@brizz/browser

中文文档
0.3.3发布于 2026/10/28Apache-2.0TypeScriptESM + CJS近 30 天下载 4万

Brizz product analytics SDK for browsers

原始使用文档
文档目录13 节
  1. Install
  2. Quick start
  3. Init options
  4. Session correlation
  5. Default session
  6. Parallel sessions
  7. Auto-context
  8. Session-replay correlation
  9. Wire format
  10. Bundle size
  11. Browser support
  12. Links
  13. License

@brizz/browser

Brizz product analytics SDK for browser apps. Emits track('event_name', {...}) calls as OpenTelemetry log records to your Brizz gateway, so frontend interactions are correlated with backend agent traces in the same Brizz session.

Lightweight and dependency-light: a small bundle, no framework lock-in, and PII masking built in. Drop it into any web app via npm or a CDN <script> tag and start sending events in a few lines.

Building analytics into a Node backend instead? Use @brizz/sdk.

Install

npm install @brizz/browser
# or
pnpm add @brizz/browser

Or via CDN:

<script src="https://unpkg.com/@brizz/browser/dist/index.iife.js"></script>
<script>
  const brizz = Brizz.init({ dsn: 'https://[email protected]/acme-web' });
  brizz.setSessionId('session-from-your-backend');
  brizz.track('clicked_submit', { plan: 'pro' });
</script>

Quick start

import { Brizz } from '@brizz/browser';

const brizz = Brizz.init({
  dsn: 'https://[email protected]/<service-name>',
});

// Same session_id your backend uses on agent traces:
brizz.setSessionId('session-from-your-backend');

brizz.track('clicked_submit', { plan: 'pro', step: 'checkout' });

Init options

OptionTypeNotes
dsnstringClient DSN URL: https://brizz-ing-c-<bearer>@<host>/<service>. Mutually exclusive with apiKey/baseUrl/appName.
apiKeystringBearer token. Use instead of dsn if you prefer explicit options. Must be a Client DSN (brizz-ing-c-).
baseUrlstringGateway origin, e.g. https://telemetry.brizz.dev. Required without dsn.
appNamestringService name; becomes service.name. Required without dsn.
disableBatchbooleanFlush each event immediately. Default false (events batch for ~5 sec).
logLevel'debug' | 'info' | 'warn' | 'error' | 'none'Default 'warn'.
maskingboolean | objectEnable PII masking with built-in patterns (true) or supply a custom config.
headersRecord<string, string>Optional extra HTTP headers attached to each OTLP request.

Session correlation

The browser SDK does not mint, rotate, or persist session ids. You decide where the id comes from — typically your own backend mints it and propagates it to both the frontend (this SDK) and your agent backend (the Node SDK). Each track() call attaches the id as LogAttributes['brizz.session.id'] (canonical Brizz key — same one the Node SDK uses) so Brizz can join the two halves in the dashboard. The event name is similarly mirrored into LogAttributes['event.name'].

Default session

For the common single-session case, set the id once and every subsequent track() uses it:

brizz.setSessionId('whatever-the-customer-decides'); // sticky across track() calls
brizz.track('clicked_submit', { plan: 'pro' });
brizz.setSessionId(null); // e.g. on logout

Parallel sessions

When a single page hosts more than one logical session (e.g. two chat widgets, side-by-side compares, an in-product copilot opened alongside a support chat), use brizz.session(id) to get a session-bound emitter. Every track() on that emitter stamps the bound id, independent of the default.

const supportChat = brizz.session('support-thread-7');
const copilot = brizz.session('copilot-session-42');

supportChat.track('typed', { length: 12 });
copilot.track('accepted_suggestion', { tool: 'rename' });

Scoped emitters are cheap — cache one per session and reuse, or create on the fly. They share the same underlying transport, so brizz.flush() flushes everything; supportChat.flush() is a convenience that delegates to the parent.

Prefer brizz.session(id) over swapping the default with setSessionId back and forth when sessions are concurrent — async event handlers crossing a swap would otherwise stamp the wrong id.

Auto-context

Every track() call automatically attaches the following attributes, all under the brizz.internal.browser.* namespace:

  • brizz.internal.browser.current_url, brizz.internal.browser.referrer, brizz.internal.browser.page_title
  • brizz.internal.browser.browser, brizz.internal.browser.browser_version, brizz.internal.browser.os, brizz.internal.browser.os_version, brizz.internal.browser.user_agent
  • brizz.internal.browser.locale, brizz.internal.browser.screen_width, brizz.internal.browser.screen_height

These come from window, document, navigator, and screen at the moment the event fires.

Session-replay correlation

If your page also runs FullStory, Mixpanel Session Replay, or LogRocket, Brizz auto-correlates the recording with the matching session. A deep-link badge appears on the Brizz session in the dashboard — one click to the replay.

ProviderSetupOpt out
FullStoryNone — auto-detected when their snippet is on the pagedisableFullStory: true
MixpanelNone — auto-detected when Session Replay is enabled on the projectdisableMixpanel: true
LogRocketNone for CDN snippet. For the npm package, see below.disableLogRocket: true

For the LogRocket npm package, add one side-effect import:

import { Brizz } from '@brizz/browser';
import '@brizz/browser/integrations/logrocket';
import LogRocket from 'logrocket';

LogRocket.init('myapp/myapp');
Brizz.init({ dsn: '...' });

Wire format

Each track() produces one OTel log record, batched by BatchLogRecordProcessor and exported as OTLP-JSON to <baseUrl>/v1/logs:

POST https://telemetry.brizz.dev/v1/logs
Authorization: Bearer brizz-ing-c-9k3xPq2v...
X-Brizz-Service-Name: acme-web
Content-Type: application/json

{ "resourceLogs": [...] }

The gateway then:

  1. Authenticates the Client DSN bearer
  2. Checks Origin against the allowed-origins for that DSN
  3. Rewrites the resource service.name from X-Brizz-Service-Name
  4. Publishes to NATS unchanged

Bundle size

The package ships in three forms:

BuildSize (gzipped)Use
ESM (dist/index.js)~8 KBnpm + bundler (Vite/Webpack/Rollup). OTel deps stay external.
CJS (dist/index.cjs)~8 KBnpm for CommonJS consumers.
IIFE (dist/index.iife.js)~19 KBCDN <script> tag. OTel deps bundled.

CI fails if either bundle exceeds its size budget (size-limit config in package.json).

Browser support

Targets ES2022 — runs in modern evergreen browsers (Chrome, Safari, Firefox, Edge).

License

Apache-2.0

版本与发布记录

@brizz/browser 共发布 6 个版本,首次发布于 2026/05/21;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.3.3latest2026/10/2811 天前
0.3.22026/09/201 个月前
0.3.12026/09/111 个月前
0.3.02026/05/275 个月前
0.2.02026/05/255 个月前
0.1.02026/05/215 个月前

关于 @brizz/browser 的常见问题

@brizz/browser 是什么?

Brizz product analytics SDK for browsers

如何安装 @brizz/browser?

在项目目录运行 npm install @brizz/browser,或使用 pnpm add / yarn add / bun add。

@brizz/browser 支持 TypeScript 吗?

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

@brizz/browser 支持 ESM 还是 CommonJS?

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

@brizz/browser 需要什么版本的 Node.js?

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

@brizz/browser 可以商用吗?

@brizz/browser 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@brizz/browser 的下载量有多少?

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

@brizz/browser 还在维护吗?

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