@automattic/node-tracks

中文文档
0.7.1发布于 2026/10/07MITTypeScriptCommonJS零依赖近 30 天下载 2114

Tracks wrapper for NodeJS

原始使用文档

Node Tracks

npm

A Tracks wrapper for NodeJS

⚠️⚠️⚠️⚠️ This library is for internal use at Automattic only. Join us! ⚠️⚠️⚠️⚠️

How to use

Requires Node.js 22 or newer.

import tracker from '@automattic/node-tracks';

const trackEvent = tracker( '<valid_event_prefix>', { _ut: '<valid_event_user_type>' } ).trackEvent;
// tracker takes 2 arguments
// prefix (string): all your events will be prefixed with this
// globalParams (object): this is a global object that will be sent with all requests. `_ut` is required

trackEvent( 'eventName', extraParams, logger );
// trackEvent takes 3 arguments
// eventName (string) : Your event name
// extraParams (object): Any extra params
// logger (optional): will log to the console otherwise

Use trackEventAndForget in short-lived commands that need a bounded delivery attempt:

const trackEventAndForget = tracker( '<valid_event_prefix>', {
    _ut: '<valid_event_user_type>',
} ).trackEventAndForget;

await trackEventAndForget( 'event_name', extraParams, logger );

trackEventAndForget uses a non-keep-alive request and closes the response after its headers arrive. This prevents the response socket from keeping a CLI alive. Its default hard timeout is 500 ms. Pass a custom timeout in milliseconds as the fourth argument. A timeout or network failure closes the request and response and resolves the Promise. Telemetry failure does not change caller control flow. A slow DNS lookup can still keep the process alive after the Promise resolves.

Please refer to this table for a list of all extraParams

Contributing

See CONTRIBUTING.md for details on development, testing, publishing, etc.

版本与发布记录

@automattic/node-tracks 共发布 11 个版本,首次发布于 2020/12/23;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.7.1latest2026/10/071 个月前
0.7.02026/08/312 个月前
0.6.42026/05/165 个月前
0.6.12025/08/181.2 年前
0.6.02025/08/181.2 年前
0.5.02023/10/313 年前

关于 @automattic/node-tracks 的常见问题

@automattic/node-tracks 是什么?

Tracks wrapper for NodeJS

如何安装 @automattic/node-tracks?

在项目目录运行 npm install @automattic/node-tracks,或使用 pnpm add / yarn add / bun add。

@automattic/node-tracks 支持 TypeScript 吗?

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

@automattic/node-tracks 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@automattic/node-tracks 需要什么版本的 Node.js?

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

@automattic/node-tracks 可以商用吗?

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

@automattic/node-tracks 的下载量有多少?

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

@automattic/node-tracks 还在维护吗?

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