纽 约 总 部
这个 营销分析浏览器 SDK 目前处于维护模式。 振幅引入了 浏览器 SDK 2.0 作为它的替代。 这个SDK提供改进的营销属性跟踪,简化的界面,以及更轻量级的包.
欲了解浏览器2.0 SDK的更多信息,请访问一些有用的链接:
- 国家防范机制:https://www.npmjs.com/package/@amplitude/analytics-browser
- GitHub : (中文(简体) ) https://github.com/amplitude/Ampludium-TypeScript 互联网档案馆的存檔,存档日期2013-12-22
- 联合国 https://www.docs.developers.amplitude.com/data/sdks/browser-2. 页面存档备份,存于互联网档案馆
请检查access-date=中的日期值 (帮助) 这里。 。 。 .
@amplitude/市场营销-分析-浏览器
官方对网络和营销分析的振幅SDK
医生
看我们的 类型分析浏览器 SDK 关于所有可用的SDK方法的清单和说明的参考.
安装和快速启动
请访问我们的100:开发者中心 关于安装和使用我们的SDK的指示.
安装
要开始使用Amplitude Marketing Analytics 浏览器 SDK,通过国家防范机制或脚本加载器将软件包安装到您的项目上.
使用节点软件包
该软件包发布在国家预防机制登记册上,可用npm和纱线安装.
# npm
npm install @amplitude/marketing-analytics-browser@^1.0.0
# yarn
yarn add @amplitude/marketing-analytics-browser@^1.0.0
使用脚本加载器
或者,该包也通过CDN分发。 复制并粘贴下面的脚本到您的 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 密钥 .
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',
}
});
跟踪事件
事件代表用户如何与您的应用程序互动. 例如,"按钮点击"可能是您想要注意的动作.
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);
用户属性
用户属性帮助您理解您的用户在您的应用程序中执行某些动作时, 诸如设备细节, 偏好或语言 .
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);
预支/追加
- 附加会将一个或多个值附加到用户属性数组中.
- 预置将预置一个或数个值给用户属性.
用户组
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']);
组识别
这一特征只提供给购买该软件的成长和企业客户 账户追加。 。 。 .
使用 Group 识别 API 设置或更新特定组的属性 。 然而,这些最新情况只会影响今后的活动.
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。 这使得我们可以在平台上自动显示与收入相关的数据. 您可以用此来跟踪应用程序中的和非应用程序中的购买.
import { Revenue, revenue } from '@amplitude/marketing-analytics-browser';
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)
});
用户登录
这更新了用户ID与设备ID. 打电话后 reset() 随后的事件现在属于一个新的用户身份.
import { reset } from '@amplitude/marketing-analytics-browser';
reset();