# @amplitude/marketing-analytics-browser 中文文档

规范地址：https://npmcn.com/package/%40amplitude/marketing-analytics-browser/

版本：1\.0\.21
npm 元数据更新时间：2026-06-26T17:03:10.995Z
中文译文更新时间：2026-11-06T01:40:58.449Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40amplitude/marketing-analytics-browser
原文对照：https://npmcn.com/package/%40amplitude/marketing-analytics-browser/?lang=original
项目主页：https://github.com/amplitude/Amplitude-TypeScript
源码仓库：https://github.com/amplitude/Amplitude-TypeScript

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：416 kB，82 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：7 个
- 首次发布：2022-09-26T16:23:52.708Z
- 最新版本发布：2025-07-08T18:30:34.899Z
- 近 30 天下载量：7458（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：70（近 12 个月 0 个）

## 中文简介

官方对网络和营销分析的振幅SDK

## 安装

```sh
npm install @amplitude/marketing-analytics-browser
```

也可以使用：`pnpm add @amplitude/marketing-analytics-browser`、`yarn add @amplitude/marketing-analytics-browser`、`bun add @amplitude/marketing-analytics-browser`

## README

[![](https://static.amplitude.com/lightning/46c85bfd91905de8047f1ee65c7c93d6fa9ee6ea/static/media/amplitude-logo-with-text.4fb9e463.svg)](https://amplitude.com/)  

# 纽 约 总 部

这个 [营销分析浏览器 SDK](https://www.docs.developers.amplitude.com/data/sdks/marketing-analytics-browser/) 目前处于维护模式。 振幅引入了 [浏览器 SDK 2.0](https://www.docs.developers.amplitude.com/data/sdks/browser-2/) 作为它的替代。 这个SDK提供改进的营销属性跟踪,简化的界面,以及更轻量级的包.

欲了解浏览器2.0 SDK的更多信息,请访问一些有用的链接:

-   国家防范机制:https://www.npmjs.com/package/@amplitude/analytics-browser
-   GitHub : (中文(简体) ) [https://github.com/amplitude/Ampludium-TypeScript 互联网档案馆的存檔,存档日期2013-12-22](https://github.com/amplitude/Amplitude-TypeScript)
-   联合国 [https://www.docs.developers.amplitude.com/data/sdks/browser-2. 页面存档备份,存于互联网档案馆](https://www.docs.developers.amplitude.com/data/sdks/browser-2/)

请检查access-date=中的日期值 (帮助) [这里](https://www.docs.developers.amplitude.com/data/sdks/marketing-analytics-browser/migration)。 。 。 .

# @amplitude/市场营销-分析-浏览器

官方对网络和营销分析的振幅SDK

# 医生

看我们的 [类型分析浏览器 SDK](https://amplitude.github.io/Amplitude-TypeScript/modules/_amplitude_marketing_analytics_browser.html) 关于所有可用的SDK方法的清单和说明的参考.

# 安装和快速启动

请访问我们的100:[开发者中心](https://www.docs.developers.amplitude.com/data/sdks/marketing-analytics-browser/) 关于安装和使用我们的SDK的指示.

## 安装

要开始使用Amplitude Marketing Analytics 浏览器 SDK,通过国家防范机制或脚本加载器将软件包安装到您的项目上.

### 使用节点软件包

该软件包发布在国家预防机制登记册上,可用npm和纱线安装.

```sh
# npm
npm install @amplitude/marketing-analytics-browser@^1.0.0

# yarn
yarn add @amplitude/marketing-analytics-browser@^1.0.0
```

### 使用脚本加载器

或者,该包也通过CDN分发。 复制并粘贴下面的脚本到您的 html 文件 .

```html
<script type="text/javascript">
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},o=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},s=function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})},i=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(o(e,t,Array.prototype.slice.call(arguments)))};s(e,t,Array.prototype.slice.call(arguments))}},a=function(e){for(var t=0;t<y.length;t++)i(e,y[t],!1);for(var r=0;r<g.length;r++)i(e,g[r],!0)};r.invoked=!0;var u=t.createElement("script");u.type="text/javascript",u.integrity="sha384-GHMjupGoiEYbVNhlFaV8TE8oh4dmGkFVo8tK74+jPpn7juCuO7mO6vzBaDJNAxuz",u.crossOrigin="anonymous",u.async=!0,u.src="https://cdn.amplitude.com/libs/marketing-analytics-browser-1.0.21-min.js.gz",u.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var c=t.getElementsByTagName("script")[0];c.parentNode.insertBefore(u,c);for(var l=function(){return this._q=[],this},p=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<p.length;d++)n(l,p[d]);r.Identify=l;for(var f=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],m=0;m<v.length;m++)n(f,v[m]);r.Revenue=f;var y=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],g=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];a(r),r.createInstance=function(e){return r._iq[e]={_q:[]},a(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();

amplitude.init("YOUR_API_KEY_HERE");
</script>
```

## 使用量

### 初始化 SDK

在进行任何仪器处理之前,必须先初始化。 您的振幅工程需要 API 密钥 .

```typescript
amplitude.init(API_KEY);

// Config web attribution and auto page view tracking
amplitude.init(API_KEY, USER_ID, {
  // Config web attribution
  attribution: {
    resetSessionOnNewCampaign: true;
  },

  // Enable auto page view tracking
  pageViewTracking: {
    trackOn: 'attribution',
  }
});
```

### 跟踪事件

事件代表用户如何与您的应用程序互动. 例如,"按钮点击"可能是您想要注意的动作.

```typescript
import { track } from '@amplitude/marketing-analytics-browser';

// Track a basic event
track('Button Clicked');

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

### 用户属性

用户属性帮助您理解您的用户在您的应用程序中执行某些动作时, 诸如设备细节, 偏好或语言 .

```typescript
import { Identify, identify } from '@amplitude/marketing-analytics-browser';

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);
```

### 预支/追加

-   附加会将一个或多个值附加到用户属性数组中.
-   预置将预置一个或数个值给用户属性.

### 用户组

```typescript
import { setGroup } from '@amplitude/marketing-analytics-browser';

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

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

### 组识别

这一特征只提供给购买该软件的成长和企业客户 [账户追加](https://amplitude.zendesk.com/hc/en-us/articles/115001765532)。 。 。 .

使用 Group 识别 API 设置或更新特定组的属性 。 然而,这些最新情况只会影响今后的活动.

```typescript
import { Identify, groupIdentify } from '@amplitude/marketing-analytics-browser';

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

groupIdentify(groupType, groupName, identify);
```

### 轨道收入

收入实例将存储每笔收入交易, 并允许您定义一些特殊的收入属性( 如“ 收益类型 ” 、 “ 产品标识符 ” 等) , 用于 Amplitude 的事件分割和收入 LTV 图表 。 这些税收实例对象随后被传递到 `revenue` 以收入方式发送到Amplition。 这使得我们可以在平台上自动显示与收入相关的数据. 您可以用此来跟踪应用程序中的和非应用程序中的购买.

```typescript
import { Revenue, revenue } from '@amplitude/marketing-analytics-browser';

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

revenue(event);
```

### 回电

所有同步的API通过特定的"承诺"接口可选择等待. 这也作为回调接口.

```typescript
// 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)
});
```

### 用户登录

这更新了用户ID与设备ID. 打电话后 `reset()` 随后的事件现在属于一个新的用户身份.

```typescript
import { reset } from '@amplitude/marketing-analytics-browser';

reset();
```

## 常见问题

### @amplitude/marketing-analytics-browser 是什么？

官方对网络和营销分析的振幅SDK

### 如何安装 @amplitude/marketing-analytics-browser？

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

### @amplitude/marketing-analytics-browser 支持 TypeScript 吗？

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

### @amplitude/marketing-analytics-browser 支持 ESM 还是 CommonJS？

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

### @amplitude/marketing-analytics-browser 可以商用吗？

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

### @amplitude/marketing-analytics-browser 的下载量有多少？

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

### @amplitude/marketing-analytics-browser 还在维护吗？

最新版本 1\.0\.21 发布于 2025/07/09（1\.3 年前）；至今共发布 70 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/09/27。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

