@amplitude/analytics-node

中文文档
1.5.83发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 472.8万

Official Amplitude SDK for NodeJS

原始使用文档
文档目录11 节
  1. Installation
  2. Using Node package
  3. Usage
  4. Initializing SDK
  5. Tracking an Event
  6. User Properties
  7. prepend/append
  8. User Groups
  9. Group Identify
  10. Track Revenue
  11. Callback


@amplitude/analytics-node

Official Amplitude SDK for Node.js

Doc

See our Typescript Analytics Node SDK Reference for a list and description of all available SDK methods.

Installation and Quick Start

Please visit our :100:Developer Center for instructions on installing and using our the SDK.

Installation

To get started with using Amplitude Node.js SDK, install the package to your project via NPM.

Using Node package

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

# npm
npm install @amplitude/analytics-node@^1.0.0

# yarn
yarn add @amplitude/analytics-node@^1.0.0

Usage

Initializing SDK

Initialization is necessary before any instrumentation is done. The API key for your Amplitude project is required.

amplitude.init(API_KEY);

Tracking an Event

Events represent how users interact with your application. For example, "Button Clicked" may be an action you want to note.

import { track } from '@amplitude/analytics-node';

// Track a basic event
track('Button Clicked', undefined, {
  user_id: '[email protected]',
});

// Track events with additional properties
const eventProperties = {
  selectedColors: ['red', 'blue'],
};
track('Button Clicked', eventProperties, {
  user_id: '[email protected]',
});

User Properties

User properties help you understand your users at the time they performed some action within your app such as their device details, their preferences, or language.

import { Identify, identify } from '@amplitude/analytics-node';

const event = new Identify();

// sets the value of a user property
event.set('key1', 'value1');

// sets the value of a user property only once
event.setOnce('key1', 'value1');

// increments a user property by some numerical value.
event.add('value1', 10);

// pre inserts a value or values to a user property
event.preInsert('ab-tests', 'new-user-test');

// post inserts a value or values to a user property
event.postInsert('ab-tests', 'new-user-test');

// removes a value or values to a user property
event.remove('ab-tests', 'new-user-test')

// sends identify event
identify(event);

prepend/append

  • append will append a value or values to a user property array.
  • prepend will prepend a value or values to a user property.

User Groups

import { setGroup } from '@amplitude/analytics-node';

// set group with single group name
setGroup('orgId', '15');

// set group with multiple group names
setGroup('sport', ['soccer', 'tennis']);

Group Identify

This feature is only available to Growth and Enterprise customers who have purchased the Accounts add-on.

Use the Group Identify API to set or update properties of particular groups. However, these updates will only affect events going forward.

import { Identify, groupIdentify } from '@amplitude/analytics-node';

const groupType = 'plan';
const groupName = 'enterprise';
const identity = new Identify()
identity.set('key1', 'value1');

groupIdentify(groupType, groupName, identity);

Track Revenue

Revenue instances will store each revenue transaction and allow you to define several special revenue properties (such as 'revenueType', 'productIdentifier', etc.) that are used in Amplitude's Event Segmentation and Revenue LTV charts. These Revenue instance objects are then passed into revenue to send as revenue events to Amplitude. This allows us to automatically display data relevant to revenue in the platform. You can use this to track both in-app and non-in-app purchases.

import { Revenue, revenue } from '@amplitude/analytics-node';

const event = new Revenue()
  .setProductId('com.company.productId')
  .setPrice(3.99)
  .setQuantity(3);

revenue(event);

Callback

All asynchronous API are optionally awaitable through a specific Promise interface. This also serves as callback interface.

// Using async/await
const results = await track('Button Clicked').promise;
result.event; // {...} (The final event object sent to Amplitude)
result.code; // 200 (The HTTP response status code of the request.
result.message; // "Event tracked successfully" (The response message)

// Using promises
track('Button Clicked').promise.then((result) => {
  result.event; // {...} (The final event object sent to Amplitude)
  result.code; // 200 (The HTTP response status code of the request.
  result.message; // "Event tracked successfully" (The response message)
});

版本与发布记录

@amplitude/analytics-node 共发布 167 个版本,首次发布于 2022/07/23;过去 12 个月发布了 90 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

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

其他发布通道:SR-1975 → 1.5.22-SR-1975.0,zen-observable-migration → 1.5.23-zen-observable-migration.0,zen-plus-zoning → 1.5.23-zen-plus-zoning.2,pnpm-migration → 1.5.30-pnpm-migration.0,feat-zoning-010526 → 1.5.30-feat-zoning-010526.0,fake-branch-1141 → 1.5.30-fake-branch-1141.0。

关于 @amplitude/analytics-node 的常见问题

@amplitude/analytics-node 是什么?

Official Amplitude SDK for NodeJS

如何安装 @amplitude/analytics-node?

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

@amplitude/analytics-node 支持 TypeScript 吗?

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

@amplitude/analytics-node 支持 ESM 还是 CommonJS?

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

@amplitude/analytics-node 可以商用吗?

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

@amplitude/analytics-node 的下载量有多少?

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

@amplitude/analytics-node 还在维护吗?

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