@amplitude/plugin-web-vitals-browser

中文文档
1.2.9发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 881.8万
原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. 2. Instantiate the plugin
  4. 3. Install plugin to Amplitude SDK
  5. 4. Initialize Amplitude SDK


@amplitude/plugin-web-vitals-browser (beta)

This plugin is in beta at the moment, naming and interface might change in the future.

Autocaptures web-vitals metrics (INP, LCP, FCP, CLS)

Installation

This package is published on NPM registry and is available to be installed using npm and yarn.

# npm
npm install @amplitude/plugin-web-vitals-browser@beta

# yarn
yarn add @amplitude/plugin-web-vitals-browser@beta

Usage

import * as amplitude from '@amplitude/analytics-browser';
import { webVitalsPlugin } from '@amplitude/plugin-web-vitals-browser';

2. Instantiate the plugin

const plugin = webVitalsPlugin();

Options

NameTypeDefaultDescription
reportSoftNavbooleanfalseAlso report web vitals for soft navigations, not only for the initial page load.
reportSoftNav

Single page applications update the URL and history without a full page navigation, so by default Core Web Vitals are only measured once, for the initial page load. With reportSoftNav enabled, LCP, FCP, INP, CLS and TTFB are also measured per soft navigation, and one [Amplitude] Web Vitals event is sent per navigation, with the page properties of the URL the metrics belong to. Metrics measured for a soft navigation have a navigationType of soft-navigation.

const plugin = webVitalsPlugin({ reportSoftNav: true });

This requires browser support for the Soft Navigations API (Chromium 151+). In browsers without it, reporting is unchanged from the default behavior.

Note that enabling this also changes how the initial page load is measured: its metrics are finalized once the first soft navigation occurs, rather than when the page is hidden.

When using the Browser SDK's autocapture, the same option can be set through autocapture.webVitals:

amplitude.init('API_KEY', {
  autocapture: {
    webVitals: { reportSoftNav: true },
  },
});

3. Install plugin to Amplitude SDK

amplitude.add(plugin);

4. Initialize Amplitude SDK

amplitude.init('API_KEY');

版本与发布记录

@amplitude/plugin-web-vitals-browser 共发布 129 个版本,首次发布于 2025/05/31;过去 12 个月发布了 91 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.9latest2026/11/071 天前
1.2.9-sr-bfcache-pageshow-snapshot.02026/11/052 天前
1.2.82026/10/317 天前
1.2.8-video-analytics-8.02026/10/2811 天前
1.2.8-video-analytics-7.02026/10/2712 天前
1.2.8-codexsemantic-review-integration.02026/10/2315 天前

其他发布通道:frustrationanalytics → 0.1.0-frustrationanalytics.0,SR-1975 → 0.1.0-SR-1975.0,beta → 0.1.0-beta.35,zen-observable-migration → 0.1.0-zen-observable-migration.0,zen-plus-zoning → 1.0.1-zen-plus-zoning.2,alpha → 1.1.4。

关于 @amplitude/plugin-web-vitals-browser 的常见问题

如何安装 @amplitude/plugin-web-vitals-browser?

在项目目录运行 npm install @amplitude/plugin-web-vitals-browser,或使用 pnpm add / yarn add / bun add。

@amplitude/plugin-web-vitals-browser 支持 TypeScript 吗?

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

@amplitude/plugin-web-vitals-browser 支持 ESM 还是 CommonJS?

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

@amplitude/plugin-web-vitals-browser 可以商用吗?

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

@amplitude/plugin-web-vitals-browser 的下载量有多少?

根据 npm 官方下载统计,@amplitude/plugin-web-vitals-browser 在 2026/10/06 – 2026/11/04 这 30 天内被下载 8,818,015 次,日均约 293,934 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amplitude/plugin-web-vitals-browser 还在维护吗?

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