@amplitude/分析-节点
节点的正宽度 SDK
医生
看我们的 字型分析节点 SDK 关于所有可用的SDK方法的清单和说明的参考.
安装和快速启动
请访问我们的100:开发者中心 关于安装和使用我们的SDK的指示.
安装
为了开始使用Amplitude Node.js SDK,通过国家预防机制将软件包安装到你的项目上.
使用节点软件包
该软件包发布在国家预防机制登记册上,可用npm和纱线安装.
# npm
npm install @amplitude/analytics-node@^1.0.0
# yarn
yarn add @amplitude/analytics-node@^1.0.0
使用量
初始化 SDK
在进行任何仪器处理之前,必须先初始化。 您的振幅工程需要 API 密钥 .
amplitude.init(API_KEY);
跟踪事件
事件代表用户如何与您的应用程序互动. 例如,"按钮点击"可能是您想要注意的动作.
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]',
});
用户属性
用户属性帮助您理解您的用户在您的应用程序中执行某些动作时, 诸如设备细节, 偏好或语言 .
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);
预支/追加
- 附加会将一个或多个值附加到用户属性数组中.
- 预置将预置一个或数个值给用户属性.
用户组
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 识别 API 设置或更新特定组的属性 。 然而,这些最新情况只会影响今后的活动.
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);
轨道收入
收入实例将存储每笔收入交易, 并允许您定义一些特殊的收入属性( 如“ 收益类型 ” 、 “ 产品标识符 ” 等) , 用于 Amplitude 的事件分割和收入 LTV 图表 。 这些税收实例对象随后被传递到 revenue 以收入方式发送到Amplition。 这使得我们可以在平台上自动显示与收入相关的数据. 您可以用此来跟踪应用程序中的和非应用程序中的购买.
import { Revenue, revenue } from '@amplitude/analytics-node';
const event = new Revenue()
.setProductId('com.company.productId')
.setPrice(3.99)
.setQuantity(3);
revenue(event);
回电
所有同步的API通过特定的"承诺"接口可选择等待. 这也作为回调接口.
// 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)
});