@alipay-inc/mpaas-mtracker-wxmini 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +295 -0
- package/dist/index.js +2 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# 配置
|
|
2
|
+
|
|
3
|
+
1、安装npm包
|
|
4
|
+
```javascript
|
|
5
|
+
npm install @alipay-inc/mpaas-mtracker-wxmini
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
2、引入npm包
|
|
9
|
+
```javascript
|
|
10
|
+
import { Tracker } from '@alipay/mpaas-mtracker-wxmini';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
# 初始化
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
Tracker.init({
|
|
17
|
+
server: 'https://cn-hangzhou-mas-log.cloud.alipay.com/loggw/webLog.do', // 必填,接受埋点的服务地址
|
|
18
|
+
appId: 'xxxxxxxxxx', // 必填,App 唯一标识
|
|
19
|
+
workspaceId: 'default', // 必填,环境标识
|
|
20
|
+
userId: '1234567890', // 选填, 默认为空
|
|
21
|
+
bizScenario: 'alipay', // 选填,渠道来源,默认为空
|
|
22
|
+
mtrDebug: true, // 选填,是否开启 mtracker 的 debug 模式,在 debug 模式下会打印上报的日志,默认为 false 不开启
|
|
23
|
+
extendParams: { test: 111 } // 选填,全局扩展参数,默认为空,1.1.0 版本以上支持
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
# 接口
|
|
28
|
+
### Tracker.click(eventId, options)
|
|
29
|
+
**描述**:点击埋点
|
|
30
|
+
```javascript
|
|
31
|
+
Tracker.click('a1-b1', {
|
|
32
|
+
bizType: 'Pay',
|
|
33
|
+
ext: {
|
|
34
|
+
productId: 'xxx'
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
#### eventId
|
|
39
|
+
* 释义:事件ID
|
|
40
|
+
* 类型:String
|
|
41
|
+
* 示例:
|
|
42
|
+
```javascript
|
|
43
|
+
a1-b1
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### options
|
|
47
|
+
|
|
48
|
+
##### bizType
|
|
49
|
+
* 释义:业务码
|
|
50
|
+
* 类型:String
|
|
51
|
+
* 示例:
|
|
52
|
+
```javascript
|
|
53
|
+
Pay
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
##### ext
|
|
57
|
+
* 释义:扩展参数
|
|
58
|
+
* 类型:Object
|
|
59
|
+
* 示例:
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
{
|
|
63
|
+
productId: 'xxx'
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Tracker.expo(eventId, options)
|
|
68
|
+
**描述** 曝光埋点
|
|
69
|
+
```javascript
|
|
70
|
+
Tracker.expo('a1-b1', {
|
|
71
|
+
bizType: 'Pay',
|
|
72
|
+
ext: {
|
|
73
|
+
productId: 'xxx'
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
#### eventId
|
|
78
|
+
* 释义:事件ID
|
|
79
|
+
* 类型:String
|
|
80
|
+
* 示例:
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
a1-b1
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### options
|
|
87
|
+
|
|
88
|
+
##### bizType
|
|
89
|
+
* 释义:业务码
|
|
90
|
+
* 类型:String
|
|
91
|
+
* 示例:
|
|
92
|
+
```javascript
|
|
93
|
+
Pay
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
##### ext
|
|
97
|
+
* 释义:扩展参数
|
|
98
|
+
* 类型:Object
|
|
99
|
+
* 示例:
|
|
100
|
+
```javascript
|
|
101
|
+
{
|
|
102
|
+
productId: 'xxx'
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Tracker.setUserId(userId)
|
|
107
|
+
```javascript
|
|
108
|
+
Tracker.setUserId('xxx');
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Tracker.changeTrackerExtendParams(ext)
|
|
112
|
+
**描述** 改变全局扩展参数
|
|
113
|
+
> 该功能自 1.1.0 版本起支持,如需使用该功能请升级
|
|
114
|
+
```javascript
|
|
115
|
+
Tracker.changeTrackerExtendParams({
|
|
116
|
+
productId: 'xxx'
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
##### ext
|
|
120
|
+
* 释义:扩展参数
|
|
121
|
+
* 类型:Object
|
|
122
|
+
* 示例:
|
|
123
|
+
```javascript
|
|
124
|
+
{
|
|
125
|
+
productId: 'xxx'
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
# 预置扩展属性
|
|
129
|
+
|
|
130
|
+
| 属性ID | 说明 |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| userAgent | -(微信小程序内获取不到,故置为-) |
|
|
133
|
+
| fullURL | 当前页面的完整 URL |
|
|
134
|
+
| mBizScenario | 渠道来源 |
|
|
135
|
+
|
|
136
|
+
# 埋点格式
|
|
137
|
+
|
|
138
|
+
## 点击埋点
|
|
139
|
+
|
|
140
|
+
| 序号 | 字段名 | 字段值(示例) |
|
|
141
|
+
| --- | --- | --- |
|
|
142
|
+
| 01 | 日志头 | D-VM(固定值) |
|
|
143
|
+
| 02 | 当前时间 | 2020-02-12 20:12:20 |
|
|
144
|
+
| 03 | 客户端ID | 应用 ID_H5-workspaceId |
|
|
145
|
+
| 04 | 微信客户端版本号 | 1.0.0 |
|
|
146
|
+
| 05 | 日志埋点SDK版本 | 2(固定值) |
|
|
147
|
+
| 06 | 终端ID | - |
|
|
148
|
+
| 07 | 会话ID | d5557b75-ff80-4aab-86a6-9b1a522bbbce(生成uuid,存放在appInstance.globalData)|
|
|
149
|
+
| 08 | uid | 1234567890 |
|
|
150
|
+
| 09 | event | click(固定值) |
|
|
151
|
+
| 10 | - | |
|
|
152
|
+
| 11 | 上一级页面 ID|上一级页面位置 ID | url|postion |
|
|
153
|
+
| 12 | - | |
|
|
154
|
+
| 13 | - | |
|
|
155
|
+
| 14 | - | |
|
|
156
|
+
| 15 | - | |
|
|
157
|
+
| 16 | seedId | PayResults |
|
|
158
|
+
| 17 | - | |
|
|
159
|
+
| 18 | 业务码 | Pay (默认值:UserBehaviorH5) |
|
|
160
|
+
| 19 | - | |
|
|
161
|
+
| 20 | - | |
|
|
162
|
+
| 21 | - | |
|
|
163
|
+
| 22 | - | |
|
|
164
|
+
| 23 | 扩展字段 | k=v^k=v |
|
|
165
|
+
| 24 | - | |
|
|
166
|
+
| 25 | - | |
|
|
167
|
+
| 26 | utdid | Wn1111111111111111111QxL (guid-timestamp ) |
|
|
168
|
+
| 27 | - | |
|
|
169
|
+
| 28 | - | |
|
|
170
|
+
| 29 | - | |
|
|
171
|
+
| 30 | - | |
|
|
172
|
+
| 31 | - | |
|
|
173
|
+
| 32 | - | |
|
|
174
|
+
| 33 | - | |
|
|
175
|
+
| 34 | 设备型号 | SM-N9500 |
|
|
176
|
+
| 35 | 操作系统版本 | iOS |
|
|
177
|
+
| 36 | - | |
|
|
178
|
+
| 37 | - | |
|
|
179
|
+
| 38 | - | |
|
|
180
|
+
| 39 | 操作系统语言 | en |
|
|
181
|
+
| 40 | - | |
|
|
182
|
+
| 41 | CPU 核数 | - |
|
|
183
|
+
| 42 | - | |
|
|
184
|
+
| 43 | - | |
|
|
185
|
+
| 44 | - | |
|
|
186
|
+
| 45 | - | |
|
|
187
|
+
| 46 | 分辨率 | `1920x1200` |
|
|
188
|
+
| 47 | - | |
|
|
189
|
+
| 48 | - | |
|
|
190
|
+
|
|
191
|
+
## 曝光埋点
|
|
192
|
+
|
|
193
|
+
| 序号 | 字段名 | 字段值(示例) |
|
|
194
|
+
| --- | --- | --- |
|
|
195
|
+
| 01 | 日志头 | D-VM(固定值) |
|
|
196
|
+
| 02 | 当前时间 | 2020-02-12 20:12:20 |
|
|
197
|
+
| 03 | 客户端ID | 应用 ID_H5-workspaceId |
|
|
198
|
+
| 04 | 微信客户端版本号 | 1.0.0 |
|
|
199
|
+
| 05 | 日志埋点SDK版本 | 2(固定值) |
|
|
200
|
+
| 06 | 终端ID | - |
|
|
201
|
+
| 07 | 会话ID | d5557b75-ff80-4aab-86a6-9b1a522bbbce(生成uuid,存放在appInstance.globalData)|
|
|
202
|
+
| 08 | uid | 1234567890 |
|
|
203
|
+
| 09 | event | exposure(固定值) |
|
|
204
|
+
| 10 | - | |
|
|
205
|
+
| 11 | 上一级页面 ID|上一级页面位置 ID | url|postion |
|
|
206
|
+
| 12 | - | |
|
|
207
|
+
| 13 | - | |
|
|
208
|
+
| 14 | - | |
|
|
209
|
+
| 15 | - | |
|
|
210
|
+
| 16 | seedId | PayResults |
|
|
211
|
+
| 17 | - | |
|
|
212
|
+
| 18 | 业务码 | Pay (默认值:UserBehaviorH5) |
|
|
213
|
+
| 19 | - | |
|
|
214
|
+
| 20 | - | |
|
|
215
|
+
| 21 | - | |
|
|
216
|
+
| 22 | - | |
|
|
217
|
+
| 23 | 扩展字段 | k=v^k=v |
|
|
218
|
+
| 24 | - | |
|
|
219
|
+
| 25 | - | |
|
|
220
|
+
| 26 | utdid | Wn1111111111111111111QxL (guid-timestamp ) |
|
|
221
|
+
| 27 | - | |
|
|
222
|
+
| 28 | - | |
|
|
223
|
+
| 29 | - | |
|
|
224
|
+
| 30 | - | |
|
|
225
|
+
| 31 | - | |
|
|
226
|
+
| 32 | - | |
|
|
227
|
+
| 33 | - | |
|
|
228
|
+
| 34 | 设备型号 | SM-N9500 |
|
|
229
|
+
| 35 | 操作系统版本 | iOS |
|
|
230
|
+
| 36 | - | |
|
|
231
|
+
| 37 | - | |
|
|
232
|
+
| 38 | - | |
|
|
233
|
+
| 39 | 操作系统语言 | en |
|
|
234
|
+
| 40 | - | |
|
|
235
|
+
| 41 | CPU 核数 | - |
|
|
236
|
+
| 42 | - | |
|
|
237
|
+
| 43 | - | |
|
|
238
|
+
| 44 | - | |
|
|
239
|
+
| 45 | - | |
|
|
240
|
+
| 46 | 分辨率 | `1920x1200` |
|
|
241
|
+
| 47 | - | |
|
|
242
|
+
| 48 | - | |
|
|
243
|
+
|
|
244
|
+
## 页面打开自动化埋点
|
|
245
|
+
|
|
246
|
+
| 序号 | 字段名 | 字段值(示例) |
|
|
247
|
+
| --- | --- | --- |
|
|
248
|
+
| 01 | 日志头 | D-VM(固定值) |
|
|
249
|
+
| 02 | 当前时间 | 2020-02-12 20:12:20 |
|
|
250
|
+
| 03 | 客户端ID | 应用 ID_H5-workspaceId |
|
|
251
|
+
| 04 | 微信客户端版本号 | 1.0.0 |
|
|
252
|
+
| 05 | 日志埋点SDK版本 | 2(固定值) |
|
|
253
|
+
| 06 | 终端ID | - |
|
|
254
|
+
| 07 | 会话ID | d5557b75-ff80-4aab-86a6-9b1a522bbbce(生成uuid,存放在appInstance.globalData)|
|
|
255
|
+
| 08 | uid | 1234567890 |
|
|
256
|
+
| 09 | event | auto_openPage(固定值) |
|
|
257
|
+
| 10 | - | |
|
|
258
|
+
| 11 | 上一级页面 ID|上一级页面位置 ID | url|postion |
|
|
259
|
+
| 12 | - | |
|
|
260
|
+
| 13 | - | |
|
|
261
|
+
| 14 | - | |
|
|
262
|
+
| 15 | - | |
|
|
263
|
+
| 16 | 当前页面URL | https://d.alipay.com |
|
|
264
|
+
| 17 | - | |
|
|
265
|
+
| 18 | 业务码 | Pay (默认值:UserBehaviorH5) |
|
|
266
|
+
| 19 | - | |
|
|
267
|
+
| 20 | - | |
|
|
268
|
+
| 21 | - | |
|
|
269
|
+
| 22 | - | |
|
|
270
|
+
| 23 | 扩展字段(仅包含预置属性) | k=v^k=v |
|
|
271
|
+
| 24 | - | |
|
|
272
|
+
| 25 | - | |
|
|
273
|
+
| 26 | utdid | Wn1111111111111111111QxL (guid-timestamp ) |
|
|
274
|
+
| 27 | - | |
|
|
275
|
+
| 28 | - | |
|
|
276
|
+
| 29 | - | |
|
|
277
|
+
| 30 | - | |
|
|
278
|
+
| 31 | - | |
|
|
279
|
+
| 32 | - | |
|
|
280
|
+
| 33 | - | |
|
|
281
|
+
| 34 | 设备型号 | SM-N9500 |
|
|
282
|
+
| 35 | 操作系统版本 | iOS |
|
|
283
|
+
| 36 | - | |
|
|
284
|
+
| 37 | - | |
|
|
285
|
+
| 38 | - | |
|
|
286
|
+
| 39 | 操作系统语言 | en |
|
|
287
|
+
| 40 | - | |
|
|
288
|
+
| 41 | CPU 核数 | - |
|
|
289
|
+
| 42 | - | |
|
|
290
|
+
| 43 | - | |
|
|
291
|
+
| 44 | - | |
|
|
292
|
+
| 45 | - | |
|
|
293
|
+
| 46 | 分辨率 | `1920x1200` |
|
|
294
|
+
| 47 | - | |
|
|
295
|
+
| 48 | - | |
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! mTracker v1.0.0 */
|
|
2
|
+
!function(t,e){for(var r in e)t[r]=e[r]}(exports,function(t){var e={};function r(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)r.d(n,s,function(e){return t[e]}.bind(null,s));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e),r.d(e,"Tracker",(function(){return i}));var n={encodeStr:function(t){return"string"==typeof t?t.replace(/=|,|\^|\$\$/g,t=>{switch(t){case",":return"%2C";case"^":return"%5E";case"$$":return"%24%24";case"=":return"%3D";case"&&":return"%26%26";default:return" "}}):t},dateFormat:function(t){const e=t.getFullYear();let r=t.getMonth()+1;r=1===r.toString().length?"0"+r:r;let n=t.getDate();n=1===n.toString().length?"0"+n:n;let s=t.getHours();s=1===s.toString().length?"0"+s:s;let i=t.getMinutes();i=1===i.toString().length?"0"+i:i;let o=t.getSeconds();return o=1===o.toString().length?"0"+o:o,`${e}-${r}-${n} ${s}:${i}:${o}.${t.getMilliseconds()}`}};class s{constructor(){this.logTag="[mTracker]",this.mtrDebug=!1,this._extParams={},this.init=this.init.bind(this),this.click=this.click.bind(this),this.expo=this.expo.bind(this),this.changeTrackerExtendParams=this.changeTrackerExtendParams.bind(this),this.setUserId=this.setUserId.bind(this)}setUserId(t){this.userId=t}init(t){this._init(t);if(this._validate().result){var e=getCurrentPages(),r=e[e.length-1].route;this._remoteLog({seedId:r,actionId:"auto_openPage",ext:this._extParams})}}click(t,e={}){const{bizType:r,ext:n}=e;this._remoteLog({seedId:t,bizType:r,ext:Object.assign(this._extParams,n),actionId:"click"})}expo(t,e){const{bizType:r,ext:n}=e;this._remoteLog({seedId:t,bizType:r,ext:Object.assign(this._extParams,n),actionId:"exposure"})}changeTrackerExtendParams(t){this._changeExt(t)}_remoteLog(t){const e=this._formatData(t);this.send({url:this.server,data:e})}_init(t){let{extendParams:e}=t||{};Object.assign(this,t),e&&("object"==typeof e?this._extParams=e||{}:console.warn("[mTracker] extendParams 格式错误"))}_changeExt(t={}){"object"==typeof t?this._extParams=t:console.warn("[mTracker] 扩展参数格式错误")}_validate(){const t=this._isValid();return t.result||console.error(this.logTag,t.message),t}_isValid(){return this.server?this.appId?this.workspaceId?{result:!0}:{result:!1,message:"请配置workspaceId"}:{result:!1,message:"请配置appId"}:{result:!1,message:"请配置mtracker服务接收地址"}}_getUrl(){const t=getCurrentPages();if(t.length>0){return t[t.length-1].route}return"-"}_formatData(t){const{seedId:e="-",ext:r={},actionId:i="-",bizType:o="UserBehaviorH5"}=t,{version:a="-",model:c="-",system:u="",language:g="-"}=s._getSystemInfo();return["D-VM",n.dateFormat(new Date),`${this.appId||""}_H5-${this.workspaceId||""}`,a,"2","-",this._getSessionId(),this.userId||"-",i,"-",s._getRefer()+"|","-","-","-","-",e,"-",o,"-","-","-","-",this._formatExtParams(r)||"-","-","-",this._getUUid(),"-","-","-","-","-","-","-",c,this._getSystemVersion(u),"-","-","-",g,"-","-","-","-","-","-",this._getScreenInfo(),"-","-"]}_getScreenInfo(){return"-"}static _getRefer(){const t=getCurrentPages();if(t.length>1){return t[t.length-2].route}return"-"}_getSystemVersion(t){let e="-";return t&&([,e="-"]=t.split(" ")),e}static _getSystemInfo(){try{return wx.getSystemInfoSync()}catch(t){console.error(this.logTag,"systemInfo.error",t)}return{}}_getSessionId(){const t=getApp(),e="__mtr-mdap__";return t.globalData[e]||(t.globalData[e]=this._guid()),t.globalData[e]}_getUUid(){const t="__mtr-mdap__";let e;try{e=wx.getStorageSync(t),e||wx.setStorageSync(t,`${this._guid()}-${Date.now()}`)}catch(t){console.error(this.logTag,"wx.storage.error",t)}return e}_guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})}_getExtJoinChar(){return"^"}_formatExtParams(t){const e=["userAgent=-","fullURL="+this._getUrl()];return this.bizScenario&&e.push("mBizScenario="+n.encodeStr(this.bizScenario)),Object.keys(t).forEach(r=>{e.push(`${r}=${n.encodeStr(t[r])}`)}),e.join(this._getExtJoinChar())}send(t){const{url:e,data:r}=t;e&&(this.mtrDebug&&console.log(this.logTag,{url:e,data:r}),wx.request({url:e,method:"POST",header:{"content-type":"application/x-www-form-urlencoded"},data:{data:r}}))}}const i=new s}]));
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alipay-inc/mpaas-mtracker-wxmini",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "webpack --config config/webpack.prod.conf.js",
|
|
8
|
+
"tar": "tar -zcvf mtracker.gz dist/ package.json",
|
|
9
|
+
"prepublish": "npm run build && npm run tar",
|
|
10
|
+
"pub": "tnpm publish"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git@gitlab.alipay-inc.com:mpaas-fe/mpaas-mtracker.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@babel/core": "^7.8.7",
|
|
23
|
+
"@babel/preset-env": "^7.8.7",
|
|
24
|
+
"ali-oss": "^6.5.1",
|
|
25
|
+
"babel-loader": "^8.0.6",
|
|
26
|
+
"chalk": "^3.0.0",
|
|
27
|
+
"webpack": "^4.41.6",
|
|
28
|
+
"webpack-cli": "^3.3.11",
|
|
29
|
+
"webpack-merge": "^4.2.2"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
]
|
|
34
|
+
}
|