@amplitude/plugin-autocapture-browser

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


@amplitude/plugin-autocapture-browser (beta)

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

Browser SDK plugin for autocapture.

Installation

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

# npm
npm install @amplitude/plugin-autocapture-browser@beta

# yarn
yarn add @amplitude/plugin-autocapture-browser@beta

Usage

This plugin works on top of the Amplitude Browser SDK, generating auto-tracked events and sending to Amplitude.

Shadow DOM: optional support via the shadowDomEnabled option (locally on elementInteractions, or via remote config). See SHADOW-DOM.md.

To use this plugin, you need to install @amplitude/analytics-browser version v1.9.1 or later.

1. Import Amplitude packages

  • @amplitude/analytics-browser
  • @amplitude/plugin-autocapture-browser
import * as amplitude from '@amplitude/analytics-browser';
import { autocapturePlugin } from '@amplitude/plugin-autocapture-browser';

2. Instantiate the plugin

The plugin accepts 1 optional parameter, which is an Object to configure the allowed tracking options.

const plugin = autocapturePlugin({
  cssSelectorAllowlist: [
    '.amp-tracking',
    '[amp-tracking]'
  ],
  pageUrlAllowlist: [
    'https://amplitude.com',
    new RegExp('https://amplitude.com/blog/*')
  ],
  pageUrlExcludelist: [
    'https://amplitude.com/admin',
    new RegExp('^https:\\/\\/amplitude\\.com\\/private\\/.*$')
  ],
});

Examples:

  • The above cssSelectorAllowlist will only allow tracking elements like:
    • <button amp-tracking>Click</button>
    • <a class="amp-tracking">Link</a>
  • The above pageUrlAllowlist will only allow the elements on URL "https://amplitude.com" or any URL matching the "https://amplitude.com/blog/*" to be tracked
  • The above pageUrlExcludelist will block tracking on URL "https://amplitude.com/admin" or any URL matching the "^https:\/\/amplitude\.com\/private\/.*$" pattern, even if they match the allowlist

Options

NameTypeDefaultDescription
cssSelectorAllowliststring[]['a', 'button', 'input', 'select', 'textarea', 'label', '[data-amp-default-track]', '.amp-default-track']When provided, only allow elements matching any selector to be tracked.
pageUrlAllowlist(string|RegExp)[]undefinedWhen provided, only allow elements matching URLs to be tracked.
pageUrlExcludelist(string|RegExp)[]undefinedWhen provided, block tracking on elements matching URLs. Takes precedence over allowlist.
shouldTrackEventResolver(actionType: ActionType, element: Element) => booleanundefinedWhen provided, overwrite all other allowlists and configurations.
dataAttributePrefixstring'data-amp-track-'Allow data attributes to be collected in event property.

3. Install plugin to Amplitude SDK

amplitude.add(plugin);

4. Initialize Amplitude SDK

amplitude.init('API_KEY');

版本与发布记录

@amplitude/plugin-autocapture-browser 共发布 184 个版本,首次发布于 2024/04/24;过去 12 个月发布了 100 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.31.3latest2026/11/17今天
1.32.0-claudeconfident-mccarthy-373nfy.02026/11/106 天前
1.31.22026/11/0710 天前
1.31.2-sr-bfcache-pageshow-snapshot.02026/11/0511 天前
1.31.12026/11/0313 天前
1.31.02026/10/3116 天前

其他发布通道:next → 1.0.0-beta.5,networkautocapture → 1.2.0-networkautocapture.0,fixtypedefinition → 1.2.0-fixtypedefinition.0,networkautocapture-1 → 1.2.0-networkautocapture-1.0,usenetworkcaptureinanalyticsbrowser-1 → 1.2.1-usenetworkcaptureinanalyticsbrowser-1.0,prereleasenetworkcapture → 1.2.7-prereleasenetworkcapture.0。

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

如何安装 @amplitude/plugin-autocapture-browser?

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

@amplitude/plugin-autocapture-browser 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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