@fle-sdk/event-tracking-web 1.1.1 → 1.2.0-beta.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 +142 -133
- package/lib/index.esm.js +1 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +22 -42
- package/lib/types/tools.d.ts +8 -11
- package/lib/types/type.d.ts +93 -51
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
# @fle.sdk/event-tracking-web
|
|
2
1
|
> **构建用户数据体系,让用户行为数据发挥深远的价值。**
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
|
|
5
4
|
## 前言
|
|
6
5
|
**WEB数据埋点sdk,开始之前请确保了解埋点的架构和基础知识**
|
|
7
6
|
> 埋点中比较重要的组成部分就是每个事件的 key,注意的是 key 至少由两部分组成。
|
|
@@ -9,10 +8,8 @@
|
|
|
9
8
|
|
|
10
9
|
- appkey:APP应用唯一标识
|
|
11
10
|
- pagekey:页面唯一标识,默认取当前路由
|
|
12
|
-
- partkey
|
|
13
|
-
|
|
11
|
+
- partkey:控件/自定义事件唯一标识,可通过接口获取或自定义
|
|
14
12
|
|
|
15
|
-
<a name="Install"></a>
|
|
16
13
|
## 一、下载
|
|
17
14
|
```jsx
|
|
18
15
|
// npm
|
|
@@ -22,8 +19,6 @@ npm install @fle-sdk/event-tracking-web --save-dev
|
|
|
22
19
|
yarn add @fle-sdk/event-tracking-web
|
|
23
20
|
```
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
<a name="uenOv"></a>
|
|
27
22
|
## 二、全埋点
|
|
28
23
|
> 全埋点包括三种事件:Web 页面浏览、Web 元素点击、Web 页面留存时长,对应的配置如下:
|
|
29
24
|
|
|
@@ -38,9 +33,7 @@ WebTracking.init({
|
|
|
38
33
|
serverUrl: "https://xxx/push",
|
|
39
34
|
});
|
|
40
35
|
```
|
|
41
|
-
<a name="yw2Ck"></a>
|
|
42
36
|
###
|
|
43
|
-
<a name="LTcZG"></a>
|
|
44
37
|
### 2.1 元素点击
|
|
45
38
|
> 元素的点击事件上报 attr 属性中必须含有 **data-part-key** ,否则会被过滤。
|
|
46
39
|
|
|
@@ -51,9 +44,7 @@ WebTracking.init({
|
|
|
51
44
|
</button>
|
|
52
45
|
```
|
|
53
46
|
|
|
54
|
-
<br />
|
|
55
47
|
|
|
56
|
-
<a name="aNxuy"></a>
|
|
57
48
|
### 2.2 全埋点参数示例
|
|
58
49
|
> 全埋点三种类型的上报参数示例,建议都了解一下
|
|
59
50
|
|
|
@@ -61,136 +52,117 @@ WebTracking.init({
|
|
|
61
52
|
{
|
|
62
53
|
"desc": "Web 浏览页面",
|
|
63
54
|
"event": "PageView",
|
|
64
|
-
"appKey": "218844",
|
|
65
|
-
"siteId": "",
|
|
66
55
|
"itemKey": "218844.app_other",
|
|
67
|
-
"requestTime":
|
|
68
|
-
"deviceId": "
|
|
56
|
+
"requestTime": 1709524231171,
|
|
57
|
+
"deviceId": "1dd539cdea9332ebb9d5c087f9d4471f",
|
|
69
58
|
"privateParamMap": {
|
|
70
59
|
"currentUrl": "http://localhost:9999/app/other",
|
|
71
60
|
"targetUrl": null,
|
|
61
|
+
"pageWidth": 414,
|
|
62
|
+
"pageHeight": 672,
|
|
63
|
+
"screenWidth": 414,
|
|
64
|
+
"screenHeight": 672,
|
|
72
65
|
"sdkVersion": "1.1.0",
|
|
73
|
-
"pageWidth": 742,
|
|
74
|
-
"pageHeight": 867,
|
|
75
|
-
"screenWidth": 1680,
|
|
76
|
-
"screenHeight": 1050,
|
|
77
66
|
"systemsInfo": {
|
|
78
67
|
"language": "zh-CN",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"ua": "Mozilla/5.0 (
|
|
82
|
-
"navigationStart": 1638456820099,
|
|
83
|
-
"navigation": "1ms",
|
|
84
|
-
"dns": "0ms",
|
|
85
|
-
"tcp": "0ms",
|
|
86
|
-
"request": "2ms",
|
|
87
|
-
"response": "1ms"
|
|
68
|
+
"client": "iPhone, iOS 11.0, WeChat 8.0.5",
|
|
69
|
+
"platform": "h5",
|
|
70
|
+
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2310080 MicroMessenger/8.0.5 Language/zh_CN webview/17095233761068527 webdebugger port/25477 token/e60c2e75ed74647fb2c0d949c0a31774"
|
|
88
71
|
},
|
|
89
72
|
"urlParams": {},
|
|
90
73
|
"userInfo": {
|
|
91
|
-
"userId": 20211232232123
|
|
74
|
+
"userId": 20211232232123,
|
|
75
|
+
"userName": "asheng"
|
|
76
|
+
},
|
|
77
|
+
"business": {
|
|
78
|
+
"appId": "1000010"
|
|
92
79
|
}
|
|
93
80
|
}
|
|
94
81
|
}
|
|
95
|
-
|
|
82
|
+
```
|
|
83
|
+
```json
|
|
96
84
|
{
|
|
97
85
|
"desc": "Web 元素点击",
|
|
98
86
|
"event": "WebClick",
|
|
99
|
-
"appKey": "218844",
|
|
100
|
-
"siteId": "",
|
|
101
87
|
"itemKey": "218844.main.h1",
|
|
102
|
-
"requestTime":
|
|
103
|
-
"deviceId": "
|
|
88
|
+
"requestTime": 1709524472904,
|
|
89
|
+
"deviceId": "1dd539cdea9332ebb9d5c087f9d4471f",
|
|
104
90
|
"privateParamMap": {
|
|
105
|
-
"position": [
|
|
106
|
-
126,
|
|
107
|
-
87
|
|
108
|
-
],
|
|
109
91
|
"targetEle": {
|
|
110
92
|
"id": "",
|
|
111
93
|
"nodeName": "H1",
|
|
112
|
-
"className": ""
|
|
94
|
+
"className": "",
|
|
95
|
+
"position": [
|
|
96
|
+
66,
|
|
97
|
+
108
|
|
98
|
+
]
|
|
113
99
|
},
|
|
114
|
-
"pointerType": "
|
|
100
|
+
"pointerType": "",
|
|
115
101
|
"currentUrl": "http://localhost:9999/main?a=1",
|
|
116
102
|
"elementSelector": "#root > div:nth-of-type(1) > div:nth-of-type(1) > h1:nth-of-type(1)",
|
|
103
|
+
"pageWidth": 414,
|
|
104
|
+
"pageHeight": 672,
|
|
105
|
+
"screenWidth": 414,
|
|
106
|
+
"screenHeight": 672,
|
|
117
107
|
"sdkVersion": "1.1.0",
|
|
118
|
-
"pageWidth": 742,
|
|
119
|
-
"pageHeight": 867,
|
|
120
|
-
"screenWidth": 1680,
|
|
121
|
-
"screenHeight": 1050,
|
|
122
108
|
"systemsInfo": {
|
|
123
109
|
"language": "zh-CN",
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"ua": "Mozilla/5.0 (
|
|
127
|
-
"navigationStart": 1638456820099,
|
|
128
|
-
"navigation": "1ms",
|
|
129
|
-
"dns": "0ms",
|
|
130
|
-
"tcp": "0ms",
|
|
131
|
-
"request": "2ms",
|
|
132
|
-
"response": "1ms",
|
|
133
|
-
"domComplete (domLoaded)": "201ms (186ms)",
|
|
134
|
-
"loadEvent": "1ms",
|
|
135
|
-
"total (DOM)": "218ms (217ms)"
|
|
110
|
+
"client": "iPhone, iOS 11.0, WeChat 8.0.5",
|
|
111
|
+
"platform": "h5",
|
|
112
|
+
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2310080 MicroMessenger/8.0.5 Language/zh_CN webview/17095233761068527 webdebugger port/25477 token/e60c2e75ed74647fb2c0d949c0a31774"
|
|
136
113
|
},
|
|
137
114
|
"urlParams": {
|
|
138
115
|
"a": "1"
|
|
139
116
|
},
|
|
140
117
|
"userInfo": {
|
|
141
|
-
"userId": 20211232232123
|
|
118
|
+
"userId": 20211232232123,
|
|
119
|
+
"userName": "asheng"
|
|
120
|
+
},
|
|
121
|
+
"business": {
|
|
122
|
+
"appId": "1000010"
|
|
142
123
|
}
|
|
143
124
|
}
|
|
144
125
|
}
|
|
145
|
-
|
|
126
|
+
```
|
|
127
|
+
```json
|
|
146
128
|
{
|
|
147
129
|
"desc": "Web 页面浏览时长",
|
|
148
130
|
"event": "PageRetained",
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
"requestTime": 1638460554657,
|
|
153
|
-
"deviceId": "f9e3f35a6371f369a2c9f21c48dcabe8",
|
|
131
|
+
"itemKey": "218844.main",
|
|
132
|
+
"requestTime": 1709524334413,
|
|
133
|
+
"deviceId": "1dd539cdea9332ebb9d5c087f9d4471f",
|
|
154
134
|
"privateParamMap": {
|
|
135
|
+
"pageWidth": 414,
|
|
136
|
+
"pageHeight": 672,
|
|
137
|
+
"screenWidth": 414,
|
|
138
|
+
"screenHeight": 672,
|
|
155
139
|
"sdkVersion": "1.1.0",
|
|
156
|
-
"pageWidth": 742,
|
|
157
|
-
"pageHeight": 867,
|
|
158
|
-
"screenWidth": 1680,
|
|
159
|
-
"screenHeight": 1050,
|
|
160
|
-
"currentUrl": "http://localhost:9999/app/other",
|
|
161
140
|
"systemsInfo": {
|
|
162
141
|
"language": "zh-CN",
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"ua": "Mozilla/5.0 (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"
|
|
169
|
-
"tcp": "0ms",
|
|
170
|
-
"request": "2ms",
|
|
171
|
-
"response": "1ms",
|
|
172
|
-
"domComplete (domLoaded)": "201ms (186ms)",
|
|
173
|
-
"loadEvent": "1ms",
|
|
174
|
-
"total (DOM)": "218ms (217ms)"
|
|
142
|
+
"client": "iPhone, iOS 11.0, WeChat 8.0.5",
|
|
143
|
+
"platform": "h5",
|
|
144
|
+
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2310080 MicroMessenger/8.0.5 Language/zh_CN webview/17095233761068527 webdebugger port/25477 token/e60c2e75ed74647fb2c0d949c0a31774"
|
|
145
|
+
},
|
|
146
|
+
"urlParams": {
|
|
147
|
+
"a": "1"
|
|
175
148
|
},
|
|
176
|
-
"urlParams": {},
|
|
177
149
|
"userInfo": {
|
|
178
|
-
"userId": 20211232232123
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
150
|
+
"userId": 20211232232123,
|
|
151
|
+
"userName": "asheng"
|
|
152
|
+
},
|
|
153
|
+
"currentUrl": "http://localhost:9999/main?a=1",
|
|
154
|
+
"business": {
|
|
155
|
+
"appId": "1000010"
|
|
156
|
+
},
|
|
157
|
+
"retainedDuration": 103243
|
|
158
|
+
}
|
|
182
159
|
}
|
|
183
160
|
```
|
|
184
161
|
|
|
185
|
-
<br />
|
|
186
|
-
|
|
187
|
-
|
|
188
162
|
---
|
|
189
163
|
|
|
190
164
|
|
|
191
|
-
|
|
192
|
-
<a name="95185770"></a>
|
|
193
|
-
## API
|
|
165
|
+
## 三、API
|
|
194
166
|
WebTracking
|
|
195
167
|
|
|
196
168
|
- init() ---初始化
|
|
@@ -199,25 +171,22 @@ WebTracking
|
|
|
199
171
|
- track() ---自定义代码埋点上报
|
|
200
172
|
- getDeviceId() ---获取设备唯一标识
|
|
201
173
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<a name="WebTracking.init"></a>
|
|
205
174
|
### Init
|
|
206
|
-
<a name="Params"></a>
|
|
207
175
|
#### 参数
|
|
208
|
-
|
|
|
176
|
+
| **参数名** | **type** | **描述** | **是否必填** | **默认值** |
|
|
209
177
|
| --- | --- | --- | --- | --- |
|
|
210
178
|
| appKey | string | 应用唯一标识(由接口生成) | 是 | - |
|
|
211
179
|
| serverUrl | string | 数据接收地址 | 是 | - |
|
|
212
180
|
| autoTrack | boolean | 是否开启全埋点(指的是:页面浏览、元素点击事件自动上报) | 否 | false |
|
|
213
181
|
| showLog | boolean | 是否在网页控制台打印发送的数据 | 否 | false |
|
|
214
|
-
| useClientTime | boolean | 是否使用客户端系统时间 | 否 | true |
|
|
215
182
|
| sendTimeout | number | 接口发送超时时长,超过该时长未发送成功将强制取消 | 否 | 3000 |
|
|
216
183
|
| isTrackSinglePage | boolean | 是否采集单页面应用的路由变化 | 否 | false |
|
|
217
|
-
|
|
|
218
|
-
|
|
184
|
+
| contentType | string | application/json
|
|
185
|
+
application/x-www-form-urlencoded | 否 | application/x-www-form-urlencoded |
|
|
186
|
+
| business | {[key: string]: any} | 全局自定义业务参数(如果后续手动上报了业务字段,会进行合并) | 否 | - |
|
|
187
|
+
| platform | string | 手动指定应用平台类型 | 否 | - |
|
|
188
|
+
|
|
219
189
|
|
|
220
|
-
<a name="df0e1504"></a>
|
|
221
190
|
#### 例子
|
|
222
191
|
> 初始化 sdk 例子,建议在 src/App.js 中初始化,且需在**useLayoutEffect**中初始化。
|
|
223
192
|
|
|
@@ -227,13 +196,17 @@ import WebTracking from "@fle-sdk/event-tracking-web";
|
|
|
227
196
|
|
|
228
197
|
const App = () => {
|
|
229
198
|
useLayoutEffect(() => {
|
|
230
|
-
//
|
|
199
|
+
// 初始化埋点
|
|
231
200
|
WebTracking.init({
|
|
232
|
-
appKey: "
|
|
233
|
-
serverUrl: "https://www.serverHost.com/serverApi/push",
|
|
234
|
-
autoTrack: true,
|
|
201
|
+
appKey: "218844",
|
|
235
202
|
showLog: true,
|
|
236
|
-
|
|
203
|
+
autoTrack: true,
|
|
204
|
+
platform: 'h5',
|
|
205
|
+
isTrackSinglePage: true,
|
|
206
|
+
serverUrl: "https://qa-gateway.fxqifu.net/pangu/buriedpoint/record/push",
|
|
207
|
+
business: {
|
|
208
|
+
appId: "1000010",
|
|
209
|
+
}
|
|
237
210
|
});
|
|
238
211
|
}, []);
|
|
239
212
|
|
|
@@ -243,23 +216,21 @@ const App = () => {
|
|
|
243
216
|
export default App;
|
|
244
217
|
```
|
|
245
218
|
|
|
246
|
-
|
|
247
|
-
<a name="EIsxL"></a>
|
|
248
219
|
### Preset
|
|
249
220
|
> 除了不可配置appKey、serverUrl,本质上和init差不多,这么做是为了更好的区分使用场景,不产生歧义。
|
|
250
221
|
|
|
251
|
-
<a name="qnIie"></a>
|
|
252
222
|
#### 参数
|
|
253
|
-
|
|
|
223
|
+
| **参数名** | **type** | **描述** | **是否必填** | **默认值** |
|
|
254
224
|
| --- | --- | --- | --- | --- |
|
|
255
225
|
| autoTrack | boolean | 是否开启全埋点(指的是:页面浏览、元素点击事件自动上报) | 否 | false |
|
|
256
226
|
| showLog | boolean | 是否在网页控制台打印发送的数据 | 否 | false |
|
|
257
|
-
| useClientTime | boolean | 是否使用客户端系统时间 | 否 | true |
|
|
258
227
|
| sendTimeout | number | 接口发送超时时长,超过该时长未发送成功将强制取消 | 否 | 3000 |
|
|
259
228
|
| isTrackSinglePage | boolean | 是否采集单页面应用的路由变化 | 否 | false |
|
|
260
|
-
|
|
|
229
|
+
| contentType | string | application/json
|
|
230
|
+
application/x-www-form-urlencoded | 否 | application/x-www-form-urlencoded |
|
|
231
|
+
| business | {[key: string]: any} | 手动埋点参数 | 否 | {} |
|
|
232
|
+
| platform | string | 手动指定应用平台类型 | 否 | - |
|
|
261
233
|
|
|
262
|
-
<a name="mFBcr"></a>
|
|
263
234
|
#### 例子
|
|
264
235
|
```jsx
|
|
265
236
|
import React, { useLayoutEffect } from "react";
|
|
@@ -295,16 +266,12 @@ const App = () => {
|
|
|
295
266
|
export default App;
|
|
296
267
|
```
|
|
297
268
|
|
|
298
|
-
|
|
299
|
-
<a name="ivnlQ"></a>
|
|
300
269
|
### Login
|
|
301
|
-
<a name="j3Vbe"></a>
|
|
302
270
|
#### 参数
|
|
303
271
|
| 参数名 | type | 描述 | 是否必填 | 默认值 |
|
|
304
272
|
| --- | --- | --- | --- | --- |
|
|
305
|
-
|
|
|
273
|
+
| params | {[key: string]: any} | 用户信息 | 是 | - |
|
|
306
274
|
|
|
307
|
-
<a name="tN0S5"></a>
|
|
308
275
|
#### 例子
|
|
309
276
|
```jsx
|
|
310
277
|
import React, { useEffect } from "react";
|
|
@@ -313,8 +280,8 @@ import { LoginStore } from "store";
|
|
|
313
280
|
|
|
314
281
|
const Test = () => {
|
|
315
282
|
const getUserInfo = () => {
|
|
316
|
-
const
|
|
317
|
-
WebTracking.Login(
|
|
283
|
+
const userInfo = await LoginStore.getUserInfo();
|
|
284
|
+
WebTracking.Login(userInfo);
|
|
318
285
|
}
|
|
319
286
|
useEffect(() => {
|
|
320
287
|
getUserInfo()
|
|
@@ -326,13 +293,10 @@ const Test = () => {
|
|
|
326
293
|
export default Test;
|
|
327
294
|
```
|
|
328
295
|
|
|
329
|
-
<br />
|
|
330
296
|
|
|
331
|
-
|
|
332
|
-
### GetDeviceId
|
|
333
|
-
<a name="zzyLD"></a>
|
|
297
|
+
### GetDistinctId
|
|
334
298
|
#### 例子
|
|
335
|
-
>
|
|
299
|
+
> 获取设备唯一标识,当用户没有登录时即用户唯一标识
|
|
336
300
|
|
|
337
301
|
```jsx
|
|
338
302
|
import React, { useEffect } from "react";
|
|
@@ -341,7 +305,7 @@ import { LoginStore } from "store";
|
|
|
341
305
|
|
|
342
306
|
const Test = () => {
|
|
343
307
|
useEffect(() => {
|
|
344
|
-
WebTracking.
|
|
308
|
+
WebTracking.getDistinctId();
|
|
345
309
|
}, []);
|
|
346
310
|
|
|
347
311
|
return <div className="Test"></div>;
|
|
@@ -350,23 +314,18 @@ const Test = () => {
|
|
|
350
314
|
export default Test;
|
|
351
315
|
```
|
|
352
316
|
|
|
353
|
-
<br />
|
|
354
317
|
|
|
355
|
-
<a name="g6lIP"></a>
|
|
356
318
|
### Track
|
|
357
319
|
> 手动代码埋点上报
|
|
358
320
|
|
|
359
|
-
<a name="Params-1"></a>
|
|
360
321
|
#### 上报参数
|
|
361
|
-
|
|
|
322
|
+
| **参数名** | **type** | **描述** | **是否必填** | **默认值** |
|
|
362
323
|
| --- | --- | --- | --- | --- |
|
|
363
|
-
| partkey |
|
|
324
|
+
| partkey | numberstring | 上报事件 Key(由前后端协商定义或由后端接口生成,该应用下需唯一且具有一定意义,例:goods_detail_pv) | 是 | - |
|
|
364
325
|
| desc | string | 上报事件描述 | 否 | 自定义上报事件 |
|
|
365
|
-
| business |
|
|
366
|
-
|
|
326
|
+
| business | {[key: string]: any} | 上报的业务参数 | 否 | - |
|
|
367
327
|
|
|
368
328
|
|
|
369
|
-
<a name="88291229"></a>
|
|
370
329
|
#### 例子
|
|
371
330
|
```jsx
|
|
372
331
|
import React, { useEffect } from "react";
|
|
@@ -402,3 +361,53 @@ const Index = () => {
|
|
|
402
361
|
|
|
403
362
|
export default Index;
|
|
404
363
|
```
|
|
364
|
+
|
|
365
|
+
## 四、完整参数明细
|
|
366
|
+
### 4.1 request参数明细
|
|
367
|
+
| **参数名** | **type** | **描述** | **示例值** |
|
|
368
|
+
| --- | --- | --- | --- |
|
|
369
|
+
| event | string | 有四种类型的值:
|
|
370
|
+
PageViewPageRetainedCustomTrackWebClick | - |
|
|
371
|
+
| desc | string | 埋点事件描述 | - |
|
|
372
|
+
| itemKey | string | 当前埋点事件Key | appkey.pagekey.partkey |
|
|
373
|
+
| requestTime | number | 发送请求事件 | - |
|
|
374
|
+
| privateParamMap | object | 私有参数 | [查看详情](#mWMBL) |
|
|
375
|
+
| deviceId | string | 设备ID | 9ce0159574b00867c7d2c5b200bd2f60 |
|
|
376
|
+
|
|
377
|
+
#### 4.2.1 privateParamMap参数明细
|
|
378
|
+
| **参数名** | **type** | **描述** | **示例值** |
|
|
379
|
+
| --- | --- | --- | --- |
|
|
380
|
+
| currentUrl | string | 当前URL | http://localhost:9999/main |
|
|
381
|
+
| targetUrl | string | 目标URL | http://localhost:9999/app/other |
|
|
382
|
+
| business | {[key: string]: any} | 手动埋点参数 | - |
|
|
383
|
+
| targetEle | TargetEleProps | 触发元素属性 | [查看详情](#YC74u) |
|
|
384
|
+
| pageWidth | number | 页面可视区宽度 | 1440 |
|
|
385
|
+
| pageHeight | number | 页面可视区高度 | 860 |
|
|
386
|
+
| screenWidth | number | 显示屏宽度 | 1440 |
|
|
387
|
+
| screenHeight | number | 显示屏高度 | 860 |
|
|
388
|
+
| pointerType | string | 手动触发的指针类型 | mouse、touch、pen |
|
|
389
|
+
| elementSelector | string | 触发元素链路 | #root > div:nth-of-type(1) > div:nth-of-type(1) > h1:nth-of-type(1) |
|
|
390
|
+
| userInfo | {[key: string]: any} | 用户信息 | {userName: "啊盛", userId: 1001} |
|
|
391
|
+
| urlParams | string | 路由参数 | - |
|
|
392
|
+
| systemsInfo | SystemsInfoTypes | 系统信息 | [查看详情](#VHfQH) |
|
|
393
|
+
| sdkVersion | string | 埋点SDk版本 | 1.0.0 |
|
|
394
|
+
| retainedDuration | number | 页面停留时长(毫秒) | 2000 |
|
|
395
|
+
|
|
396
|
+
#### 4.2.2 TargetEleProps参数明细
|
|
397
|
+
| **参数名** | **type** | **描述** | **示例值** |
|
|
398
|
+
| --- | --- | --- | --- |
|
|
399
|
+
| nodeName | string | dom节点名称 | BUTTON |
|
|
400
|
+
| id | string | id类名 | main_btn |
|
|
401
|
+
| className | string | class类名 | fx-primary-btn |
|
|
402
|
+
| position | [number, number] | 元素触发位置:[x, y] | [100, 200] |
|
|
403
|
+
|
|
404
|
+
#### 4.2.3 SystemsInfoTypes参数明细
|
|
405
|
+
| **参数名** | **type** | **描述** | **示例值** |
|
|
406
|
+
| --- | --- | --- | --- |
|
|
407
|
+
| language | string | 系统语言 | zh-CN |
|
|
408
|
+
| network | string | 网络类型 | - |
|
|
409
|
+
| ua | string | userAgent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 |
|
|
410
|
+
| client | string | 客户端(Mac/Android/iPhone/iPad/iPod/WeChat) | Mac, MacOS 10.15.7 |
|
|
411
|
+
| platform | string | 应用平台类型,如不传会自动获取
|
|
412
|
+
枚举:h5iPadpcother | h5 |
|
|
413
|
+
|
package/lib/index.esm.js
CHANGED
|
@@ -12,5 +12,5 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
12
12
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
|
-
var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},n=new(function(n){function r(){var e=n.call(this)||this;return e.userId=null,e.currentUrl="",e.pageKey="",e.eventDescMap={PageView:"Web 浏览页面",WebClick:"Web 元素点击",PageRetained:"Web 页面浏览时长",CustomTrack:"Web 自定义代码上报"},e.init=function(t){e.preset(t);var n=window.location.pathname;e.currentUrl=window.location.href,e.pageKey=n.replace(/\//g,"_").substr(1),e.systemsInfo=e.getSystemsInfo(),e.setCookie("retainedStartTime",e.getTimeStamp())},e.preset=function(t){t instanceof Object&&e.each(t,(function(t,n){void 0!==e.config[n]&&(e.config[n]=t)})),/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-\(\)]*[\w@?^=%&/~+#-\(\)])?$/.test(e.config.serverUrl)||(e.printLog("当前 server_url 为空或不正确,只在控制台打印日志,network 中不会发数据,请配置正确的 server_url!"),e.config.showLog=!0),e.config.autoTrack?e.listener():e.unlistener()},e.login=function(t){["number","string"].includes(typeof t)&&(e.userId=t)},e.track=function(t){var n=t.desc,r=t.partkey,o=t.business,i=e.getParams({desc:n,event:"CustomTrack",itemKey:e.getItemKey(r),extroInfo:{business:o}});return e.sendAjax(i)},e.listener=function(){e.config.isTrackSinglePage&&(e.rewriteHistory(),e.addSinglePageEvent(e.onPageViewCallback)),e.each(["load","beforeunload"],(function(t){e.addEventListener(window,t,e.onPageViewCallback)})),e.addEventListener(window,"click",e.onClickCallback)},e.unlistener=function(){if(e.config.isTrackSinglePage){var t=window.history.pushState?"popstate":"hashchange";e.each(["pushState","replaceState",t],(function(t){e.removeEventListener(window,t,e.onPageViewCallback)}))}e.each(["load","beforeunload"],(function(t){e.removeEventListener(window,t,e.onPageViewCallback)})),e.removeEventListener(window,"click",e.onClickCallback)},e.onClickCallback=function(t){var n,r;if(null===(r=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.dataset)||void 0===r?void 0:r.partKey){var o=[t.pageX,t.pageY],i=t.target.id,a=t.target.className,s={id:i,nodeName:t.target.nodeName,className:a},c=e.getParams({event:"WebClick",desc:e.eventDescMap.WebClick,itemKey:e.getItemKey(t.target.dataset.partKey),extroInfo:{position:o,targetEle:s,pointerType:t.pointerType,currentUrl:e.currentUrl,elementSelector:e.getDomSelector(t.target)}});return e.sendAjax(c)}},e.onPageViewCallback=function(t){var n,r,o=window.location.origin;e.sendPageViewData(t.type,{event:"PageView",desc:e.eventDescMap.PageView,extroInfo:{currentUrl:e.currentUrl,targetUrl:(null===(n=t.arguments)||void 0===n?void 0:n[2])?o+(null===(r=t.arguments)||void 0===r?void 0:r[2]):null}}),e.currentUrl=window.location.href,e.pageKey=window.location.pathname.replace(/\//g,"_").substr(1)},e.getParams=function(n){var r=n.event,o=n.desc,i=n.itemKey,a=n.extroInfo,s=void 0===a?{}:a,c=e.config,u=c.appKey,d=c.sdkVersion,l=c.siteId,p=window.innerWidth,g=window.innerHeight,f=window.screen.width,m=window.screen.height;return{desc:o,event:r,appKey:u,siteId:l,itemKey:i||e.getItemKey(),requestTime:e.getTimeStamp(),deviceId:e.getDistinctId(),privateParamMap:t(t({},s),{sdkVersion:d,pageWidth:p,pageHeight:g,screenWidth:f,screenHeight:m,currentUrl:s.currentUrl||e.currentUrl,systemsInfo:e.systemsInfo,urlParams:e.getQueryValue(),userInfo:{userId:e.userId}})}},e.sendPageViewData=function(t,n){var r=e.getParams(n);return e.sendRetained(t),e.sendAjax(r)},e.sendAjax=function(t){var n=e.config,r=n.serverUrl,o=n.sendTimeout,i=n.contentType;return n.showLog&&e.printLog(t),new Promise((function(n,a){e.ajax({url:r,type:"POST",data:JSON.stringify(t),contentType:i,credentials:!1,timeout:o,cors:!0,success:function(e){return n(e)},error:function(e){return a(e)}})}))},e.sendRetained=function(n){var r=e.config.serverUrl,o=e.getParams({event:"PageRetained",desc:e.eventDescMap.PageRetained});if(["beforeunload","pushState","replaceState","hashchange","popstate"].indexOf(n)>=0){var i=e.getCookie("retainedStartTime"),a=i?+i:e.getTimeStamp(),s=t(t({},o),{retainedStartTime:a});"beforeunload"===n?e.sendBeacon({url:r,data:s}):e.sendAjax(s).finally((function(){return e.setCookie("retainedStartTime",e.getTimeStamp())}))}},e.getItemKey=function(t){return[e.config.appKey,e.pageKey,t?t.toString():void 0].filter((function(e){return!!e})).reduce((function(e,t){return e+(e.length?".":"")+t}),"")},e.config={sdkVersion:"1.1.0",appKey:"",siteId:"",showLog:!1,serverUrl:"",autoTrack:!1,useClientTime:!0,queueTimeout:500,sendTimeout:3e3,isTrackSinglePage:!1,contentType:"application/x-www-form-urlencoded"},e.systemsInfo={},e}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}(r,n),r.prototype.addSinglePageEvent=function(e){var t=this,n=window.history.pushState?"popstate":"hashchange";this.each(["pushState","replaceState",n],(function(n){t.addEventListener(window,n,e)}))},r}(function(){function e(){var e=this;this.getPlatformType=function(){for(var e=navigator.userAgent,t=new Array("Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"),n=!0,r=0;r<t.length;r++)if(e.indexOf(t[r])>0){n=!1;break}return n?"pc":"h5"},this.addEventListener=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,(function(t){return n.call(e,t)}),!1)},this.removeEventListener=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n):e.detachEvent&&e.detachEvent("on"+t,(function(t){return n.call(e,t)}),!0)},this.rewriteHistory=function(){var e=window.history,t=function(e){var t=window.history,n=t[e],r=new Event(e);return function(){var e=n.apply(t,arguments);return r.arguments=arguments,window.dispatchEvent(r),e}};window.history.pushState&&(e.pushState=t("pushState"),e.replaceState=t("replaceState"))},this.isArray=Array.isArray||function(e){return"[object Array]"===toString.call(e)},this.formatJsonString=function(e){try{return JSON.stringify(e,null," ")}catch(t){return JSON.stringify(e)}},this.nativeForEach=Array.prototype.forEach,this.slice=Array.prototype.slice,this.hasOwnProperty=Object.prototype.hasOwnProperty,this.breaker={},this.each=function(t,n,r){if(null==t)return!1;if(e.nativeForEach&&t.forEach===e.nativeForEach)t.forEach(n,r);else if(e.isArray(t)&&t.length===+t.length){for(var o=0,i=t.length;o<i;o++)if(o in t&&n.call(r,t[o],o,t)===e.breaker)return!1}else for(var a in t)if(e.hasOwnProperty.call(t,a)&&n.call(r,t[a],a,t)===e.breaker)return!1},this.getDomIndex=function(e){if(!e.parentNode)return-1;for(var t=0,n=e.tagName,r=e.parentNode.children,o=0;o<r.length;o++)if(r[o].tagName===n){if(e===r[o])return t;t++}return-1},this.selector=function(t){var n=t.parentNode&&9==t.parentNode.nodeType?-1:e.getDomIndex(t);return t.getAttribute&&t.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id"))?"#"+t.getAttribute("id"):t.tagName.toLowerCase()+(~n?":nth-of-type("+(n+1)+")":"")},this.getDomSelector=function(t,n){if(!t||!t.parentNode||!t.parentNode.children)return!1;n=n&&n.join?n:[];var r=t.nodeName.toLowerCase();return t&&"body"!==r&&1==t.nodeType?(n.unshift(e.selector(t)),t.getAttribute&&t.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id"))?n.join(" > "):e.getDomSelector(t.parentNode,n)):(n.unshift("body"),n.join(" > "))},this.getCookie=function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var o=n[r];" "==o.charAt(0);)o=o.substring(1,o.length);if(0==o.indexOf(t))return this._decodeURIComponent(o.substring(t.length,o.length))}return null},this.setCookie=function(e,t,n){var r,o="";n=null==n?73e3:n;var i=this.getMainHost();if(r=i?"; domain="+i:"",0!==n){var a=new Date;"s"===String(n).slice(-1)?a.setTime(a.getTime()+1e3*Number(String(n).slice(0,-1))):a.setTime(a.getTime()+24*n*60*60*1e3),o="; expires="+a.toUTCString()}function s(e){return e||!1}var c="",u="",d="";e&&(c=s(e)),t&&(u=s(t)),r&&(d=s(r)),c&&u&&(document.cookie=c+"="+encodeURIComponent(u)+o+"; path=/"+d)},this.removeCookie=function(t){e.setCookie(t,"",-1)},this.getTimeStamp=function(){return(new Date).getTime()},this.uuid=function(){return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},this.getDistinctId=function(){var t=e.getCookie("distinctId");return t||(t=e.uuid(),e.setCookie("distinctId",t),t)},this.getQueryValue=function(e){for(var t=decodeURI(window.location.href).match(new RegExp("[?&][^?&]+=[^?&]+","g"))||[],n={},r=0;r<t.length;r++){var o=t[r].replace(/\?|\&/,"").split("=");if(o[0]===e)return o[1];n[o[0]]=o[1]}return e?null:n},this.ajax=function(t){function n(e){if(!e)return"";try{return JSON.parse(e)}catch(e){return{}}}t.timeout=t.timeout||3e4,t.credentials=void 0===t.credentials||t.credentials;var r=e.xhr(t.cors);if(!r)return!1;t.type||(t.type=t.data?"POST":"GET");var o,i=t.success,a=t.error;t.success=function(e){i(e),o&&(clearTimeout(o),o=null)},t.error=function(e){a(e),o&&(clearTimeout(o),o=null)},o=setTimeout((function(){!function(){try{e.isObject(r)&&r.abort&&r.abort()}catch(t){e.printLog(t)}o&&(clearTimeout(o),o=null,t.error&&t.error(),r.onreadystatechange=null,r.onload=null,r.onerror=null)}()}),t.timeout),r.onreadystatechange=function(){try{4==r.readyState&&(r.status>=200&&r.status<300||304==r.status?t.success(n(r.responseText)):t.error(n(r.responseText),r.status),r.onreadystatechange=null,r.onload=null)}catch(e){r.onreadystatechange=null,r.onload=null}},r.open(t.type,t.url,!0);try{t.credentials&&(r.withCredentials=!0),e.isObject(t.header)&&e.each(t.header,(function(e,t){r.setRequestHeader&&r.setRequestHeader(t,e)})),t.data&&(t.cors||r.setRequestHeader&&r.setRequestHeader("X-Requested-With","XMLHttpRequest"),"application/json"===t.contentType?r.setRequestHeader&&r.setRequestHeader("Content-type","application/json; charset=UTF-8"):r.setRequestHeader&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"))}catch(t){e.printLog(t)}r.send(t.data||null)},this.xhr=function(e){return e?void 0!==window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?new XMLHttpRequest:null:void 0!==window.XMLHttpRequest?new XMLHttpRequest:null},this.sendBeacon=function(e){return"object"==typeof navigator&&"function"==typeof navigator.sendBeacon?(navigator.sendBeacon(e.url,new URLSearchParams(JSON.stringify(e.data||{}))),Promise.resolve({message:"发送成功!"})):Promise.reject({message:"不支持sendBeacon,发送失败!"})}}return e.prototype.printLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this.isObject(e[0])&&(e[0]=this.formatJsonString(e[0])),"object"==typeof console&&console.log)try{return console.log.apply(console,e)}catch(t){console.log(e[0])}},e.prototype.getSystemsInfo=function(){var e=navigator.userAgent,t=[],n={language:navigator.language},r=e.match(/MicroMessenger\/([\d\.]+)/i),o=r&&r[1]?r[1]:null,i=e.match(/(ipod).*\s([\d_]+)/i),a=e.match(/(ipad).*\s([\d_]+)/i),s=e.match(/(iphone)\sos\s([\d_]+)/i),c=e.match(/(android)\s([\d\.]+)/i),u=e.match(/(Mac OS X)\s([\d_]+)/i);t=[],c?t.push("Android "+c[2]):s?t.push("iPhone, iOS "+s[2].replace(/_/g,".")):a?t.push("iPad, iOS "+a[2].replace(/_/g,".")):i?t.push("iPod, iOS "+i[2].replace(/_/g,".")):u&&t.push("Mac, MacOS "+u[2].replace(/_/g,".")),o&&t.push("WeChat "+o),n.platform=this.getPlatformType(),n.client=t.length?t.join(", "):"Unknown";var d=e.toLowerCase().match(/ nettype\/([^ ]+)/g);return d&&d[0]&&(t=[(d=d[0].split("/"))[1]],n.network=t.length?t.join(", "):"Unknown"),n.ua=e,setTimeout((function(){var e=window.performance||window.msPerformance||window.webkitPerformance;if(e&&e.timing){var t=e.timing;t.navigationStart&&(n.navigationStart=t.navigationStart),t.navigationStart&&t.domainLookupStart&&(n.navigation=t.domainLookupStart-t.navigationStart+"ms"),t.domainLookupEnd&&t.domainLookupStart&&(n.dns=t.domainLookupEnd-t.domainLookupStart+"ms"),t.connectEnd&&t.connectStart&&(t.connectEnd&&t.secureConnectionStart?n["tcp (ssl)"]=t.connectEnd-t.connectStart+"ms ("+(t.connectEnd-t.secureConnectionStart)+"ms)":n.tcp=t.connectEnd-t.connectStart+"ms"),t.responseStart&&t.requestStart&&(n.request=t.responseStart-t.requestStart+"ms"),t.responseEnd&&t.responseStart&&(n.response=t.responseEnd-t.responseStart+"ms"),t.domComplete&&t.domLoading&&(t.domContentLoadedEventStart&&t.domLoading?n["domComplete (domLoaded)"]=t.domComplete-t.domLoading+"ms ("+(t.domContentLoadedEventStart-t.domLoading)+"ms)":n.domComplete=t.domComplete-t.domLoading+"ms"),t.loadEventEnd&&t.loadEventStart&&(n.loadEvent=t.loadEventEnd-t.loadEventStart+"ms"),t.navigationStart&&t.loadEventEnd&&(n["total (DOM)"]=t.loadEventEnd-t.navigationStart+"ms ("+(t.domComplete-t.navigationStart)+"ms)")}}),0),n},e.prototype.isObject=function(e){return null!=e&&"[object Object]"==toString.call(e)},e.prototype.isUndefined=function(e){return void 0===e},e.prototype.isString=function(e){return"[object String]"==toString.call(e)},e.prototype.isDate=function(e){return"[object Date]"==toString.call(e)},e.prototype.isBoolean=function(e){return"[object Boolean]"==toString.call(e)},e.prototype.isNumber=function(e){return"[object Number]"==toString.call(e)&&/[\d\.]+/.test(String(e))},e.prototype.isElement=function(e){return!(!e||1!==e.nodeType)},e.prototype.isFunction=function(e){if(!e)return!1;var t=toString.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t},e.prototype.isJSONString=function(e){try{JSON.parse(e)}catch(e){return!1}return!0},e.prototype._decodeURIComponent=function(e){var t=e;try{t=decodeURIComponent(e)}catch(n){t=e}return t},e.prototype.getMainHost=function(){var e="mh_"+Math.random(),t=new RegExp("(^|;)\\s*"+e+"=12345"),n=new Date(0),r=document.domain.split("."),o=[];for(o.unshift(r.pop());r.length;){o.unshift(r.pop());var i=o.join("."),a=e+"=12345;domain=."+i;if(document.cookie=a,t.test(document.cookie))return document.cookie=a+";expires="+n,i}},e}()));export default n;
|
|
15
|
+
var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},n=new(function(n){function r(){var e=n.call(this)||this;return e.userInfo=null,e.currentUrl="",e.pageKey="",e.eventDescMap={PageView:"Web 浏览页面",WebClick:"Web 元素点击",PageRetained:"Web 页面浏览时长",CustomTrack:"Web 自定义代码上报"},e.init=function(t){e.preset(t);var n=window.location.pathname;e.currentUrl=window.location.href,e.pageKey=n.replace(/\//g,"_").substr(1),e.systemsInfo=e.getSystemsInfo(t.platform),e.setCookie("retainedStartTime",e.getTimeStamp())},e.preset=function(t){t instanceof Object&&e.each(t,(function(t,n){e.initConfig.hasOwnProperty(n)&&(e.initConfig[n]=t)})),/^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-\(\)]*[\w@?^=%&/~+#-\(\)])?$/.test(e.initConfig.serverUrl)||(e.printLog("当前 server_url 为空或不正确,只在控制台打印日志,network 中不会发数据,请配置正确的 server_url!"),e.initConfig.showLog=!0),e.initConfig.autoTrack?e.listener():e.unlistener()},e.login=function(t){e.isObject(t)&&(e.userInfo=t)},e.track=function(t){var n=t.desc,r=t.partkey,i=t.business,o=e.getParams({desc:n,event:"CustomTrack",itemKey:e.getItemKey(r),privateParamMap:{business:i}});return e.sendData(o)},e.listener=function(){e.initConfig.isTrackSinglePage&&(e.rewriteHistory(),e.addSinglePageEvent(e.onPageViewCallback)),e.each(["load","beforeunload"],(function(t){e.addEventListener(window,t,e.onPageViewCallback)})),e.addEventListener(window,"click",e.onClickCallback)},e.unlistener=function(){if(e.initConfig.isTrackSinglePage){var t=window.history.pushState?"popstate":"hashchange";e.each(["pushState","replaceState",t],(function(t){e.removeEventListener(window,t,e.onPageViewCallback)}))}e.each(["load","beforeunload"],(function(t){e.removeEventListener(window,t,e.onPageViewCallback)})),e.removeEventListener(window,"click",e.onClickCallback)},e.onClickCallback=function(t){var n,r;if(null===(r=null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.dataset)||void 0===r?void 0:r.partKey){var i=[t.pageX,t.pageY],o=t.target.id,a=t.target.className,s={id:o,nodeName:t.target.nodeName,className:a,position:i},c=e.getParams({event:"WebClick",desc:e.eventDescMap.WebClick,itemKey:e.getItemKey(t.target.dataset.partKey),privateParamMap:{targetEle:s,pointerType:t.pointerType,currentUrl:e.currentUrl,elementSelector:e.getDomSelector(t.target)}});return e.sendData(c)}},e.onPageViewCallback=function(t){var n,r,i=window.location.origin,o=e.getParams({event:"PageView",desc:e.eventDescMap.PageView,privateParamMap:{currentUrl:e.currentUrl,targetUrl:(null===(n=t.arguments)||void 0===n?void 0:n[2])?i+(null===(r=t.arguments)||void 0===r?void 0:r[2]):null}});e.currentUrl=window.location.href,e.pageKey=window.location.pathname.replace(/\//g,"_").substring(1),e.sendRetained(t.type),e.sendData(o)},e.getParams=function(n){var r=n.event,i=n.desc,o=n.privateParamMap,a=void 0===o?{}:o,s=n.itemKey,c=e.initConfig.business,u=window.innerWidth,l=window.innerHeight,d=window.screen.width,p=window.screen.height;return{desc:i,event:r,itemKey:s||e.getItemKey(),requestTime:e.getTimeStamp(),deviceId:e.getDistinctId(),privateParamMap:t(t({},a),{pageWidth:u,pageHeight:l,screenWidth:d,screenHeight:p,sdkVersion:e.sdkVersion,systemsInfo:e.systemsInfo,urlParams:e.getQueryValue(),userInfo:e.userInfo,currentUrl:a.currentUrl||e.currentUrl,business:t(t({},c||{}),a.business||{})})}},e.sendData=function(t){var n=e.initConfig,r=n.serverUrl,i=n.sendTimeout,o=n.contentType;return n.showLog&&e.printLog(t),!0===e.isSupportBeaconSend()?e.sendBeacon({url:r,data:t}):new Promise((function(n,a){e.ajax({url:r,type:"POST",data:JSON.stringify(t),contentType:o,credentials:!1,timeout:i,cors:!0,success:function(e){return n(e)},error:function(e){return a(e)}})}))},e.sendRetained=function(n){var r=e.getParams({event:"PageRetained",desc:e.eventDescMap.PageRetained});if(["beforeunload","pushState","replaceState","hashchange","popstate"].indexOf(n)>=0){var i=e.getCookie("retainedStartTime"),o=i?+i:e.getTimeStamp(),a=t(t({},r),{privateParamMap:t(t({},r.privateParamMap),{retainedDuration:Math.max(r.requestTime-o,0)})});e.sendData(a),e.setCookie("retainedStartTime",e.getTimeStamp())}},e.getItemKey=function(t){return[e.initConfig.appKey,e.pageKey,t?t.toString():void 0].filter((function(e){return!!e})).reduce((function(e,t){return e+(e.length?".":"")+t}),"")},e.sdkVersion="1.1.0",e.initConfig={appKey:"",platform:void 0,showLog:!1,serverUrl:"",autoTrack:!1,sendTimeout:3e3,isTrackSinglePage:!1,contentType:"application/x-www-form-urlencoded",business:{}},e.systemsInfo={},e}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}(r,n),r.prototype.addSinglePageEvent=function(e){var t=this,n=window.history.pushState?"popstate":"hashchange";this.each(["pushState","replaceState",n],(function(n){t.addEventListener(window,n,e)}))},r}(function(){function e(){var e=this;this.getSystemsInfo=function(e){var t=navigator.userAgent,n="other",r=[],i={language:navigator.language},o=t.match(/MicroMessenger\/([\d\.]+)/i),a=o&&o[1]?o[1]:null,s=t.match(/(ipod).*\s([\d_]+)/i),c=t.match(/(ipad).*\s([\d_]+)/i),u=t.match(/(iphone)\sos\s([\d_]+)/i),l=t.match(/(android)\s([\d\.]+)/i),d=t.match(/(Windows NT)\s([\d\.]+)/i),p=t.match(/(Mac OS X)\s([\d_]+)/i);r=[],l?(r.push("Android "+l[2]),n="h5"):u?(r.push("iPhone, iOS "+u[2].replace(/_/g,".")),n="h5"):c?(r.push("iPad, iOS "+c[2].replace(/_/g,".")),n="ipad"):s?(r.push("iPod, iOS "+s[2].replace(/_/g,".")),n="h5"):d?(r.push("Windows "+d[2].replace(/_/g,".")),n="pc"):p&&(r.push("Mac, MacOS "+p[2].replace(/_/g,".")),n="pc"),a&&r.push("WeChat "+a),i.client=r.length?r.join(", "):"Unknown",i.platform=e||n;var g=t.toLowerCase().match(/ nettype\/([^ ]+)/g);return g&&g[0]&&(r=[(g=g[0].split("/"))[1]],i.network=r.length?r.join(", "):"Unknown"),i.ua=t,i},this.addEventListener=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,(function(t){return n.call(e,t)}),!1)},this.removeEventListener=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n):e.detachEvent&&e.detachEvent("on"+t,(function(t){return n.call(e,t)}),!0)},this.rewriteHistory=function(){var e=window.history,t=function(e){var t=window.history,n=t[e],r=new Event(e);return function(){var e=n.apply(t,arguments);return r.arguments=arguments,window.dispatchEvent(r),e}};window.history.pushState&&(e.pushState=t("pushState"),e.replaceState=t("replaceState"))},this.isArray=Array.isArray||function(e){return"[object Array]"===toString.call(e)},this.formatJsonString=function(e){try{return JSON.stringify(e,null," ")}catch(t){return JSON.stringify(e)}},this.nativeForEach=Array.prototype.forEach,this.slice=Array.prototype.slice,this.hasOwnProperty=Object.prototype.hasOwnProperty,this.breaker={},this.each=function(t,n,r){if(null==t)return!1;if(e.nativeForEach&&t.forEach===e.nativeForEach)t.forEach(n,r);else if(e.isArray(t)&&t.length===+t.length){for(var i=0,o=t.length;i<o;i++)if(i in t&&n.call(r,t[i],i,t)===e.breaker)return!1}else for(var a in t)if(e.hasOwnProperty.call(t,a)&&n.call(r,t[a],a,t)===e.breaker)return!1},this.getDomIndex=function(e){if(!e.parentNode)return-1;for(var t=0,n=e.tagName,r=e.parentNode.children,i=0;i<r.length;i++)if(r[i].tagName===n){if(e===r[i])return t;t++}return-1},this.selector=function(t){var n=t.parentNode&&9==t.parentNode.nodeType?-1:e.getDomIndex(t);return t.getAttribute&&t.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id"))?"#"+t.getAttribute("id"):t.tagName.toLowerCase()+(~n?":nth-of-type("+(n+1)+")":"")},this.getDomSelector=function(t,n){if(!t||!t.parentNode||!t.parentNode.children)return!1;n=n&&n.join?n:[];var r=t.nodeName.toLowerCase();return t&&"body"!==r&&1==t.nodeType?(n.unshift(e.selector(t)),t.getAttribute&&t.getAttribute("id")&&/^[A-Za-z][-A-Za-z0-9_:.]*$/.test(t.getAttribute("id"))?n.join(" > "):e.getDomSelector(t.parentNode,n)):(n.unshift("body"),n.join(" > "))},this.getCookie=function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(t))return this._decodeURIComponent(i.substring(t.length,i.length))}return null},this.setCookie=function(e,t,n){var r,i="";n=null==n?73e3:n;var o=this.getMainHost();if(r=o?"; domain="+o:"",0!==n){var a=new Date;"s"===String(n).slice(-1)?a.setTime(a.getTime()+1e3*Number(String(n).slice(0,-1))):a.setTime(a.getTime()+24*n*60*60*1e3),i="; expires="+a.toUTCString()}function s(e){return e||!1}var c="",u="",l="";e&&(c=s(e)),t&&(u=s(t)),r&&(l=s(r)),c&&u&&(document.cookie=c+"="+encodeURIComponent(u)+i+"; path=/"+l)},this.removeCookie=function(t){e.setCookie(t,"",-1)},this.getTimeStamp=function(){return(new Date).getTime()},this.uuid=function(){return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))},this.getDistinctId=function(){var t=e.getCookie("distinctId");return t||(t=e.uuid(),e.setCookie("distinctId",t),t)},this.getQueryValue=function(){for(var e=decodeURI(window.location.href).match(new RegExp("[?&][^?&]+=[^?&]+","g"))||[],t={},n=0;n<e.length;n++){var r=e[n].replace(/\?|\&/,"").split("=");t[r[0]]=r[1]}return t},this.ajax=function(t){function n(e){if(!e)return"";try{return JSON.parse(e)}catch(e){return{}}}t.timeout=t.timeout||3e4,t.credentials=void 0===t.credentials||t.credentials;var r=e.xhr(t.cors);if(!r)return!1;t.type||(t.type=t.data?"POST":"GET");var i,o=t.success,a=t.error;t.success=function(e){o(e),i&&(clearTimeout(i),i=null)},t.error=function(e){a(e),i&&(clearTimeout(i),i=null)},i=setTimeout((function(){!function(){try{e.isObject(r)&&r.abort&&r.abort()}catch(t){e.printLog(t)}i&&(clearTimeout(i),i=null,t.error&&t.error(),r.onreadystatechange=null,r.onload=null,r.onerror=null)}()}),t.timeout),r.onreadystatechange=function(){try{4==r.readyState&&(r.status>=200&&r.status<300||304==r.status?t.success(n(r.responseText)):t.error(n(r.responseText),r.status),r.onreadystatechange=null,r.onload=null)}catch(e){r.onreadystatechange=null,r.onload=null}},r.open(t.type,t.url,!0);try{t.credentials&&(r.withCredentials=!0),e.isObject(t.header)&&e.each(t.header,(function(e,t){r.setRequestHeader&&r.setRequestHeader(t,e)})),t.data&&(t.cors||r.setRequestHeader&&r.setRequestHeader("X-Requested-With","XMLHttpRequest"),"application/json"===t.contentType?r.setRequestHeader&&r.setRequestHeader("Content-type","application/json; charset=UTF-8"):r.setRequestHeader&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"))}catch(t){e.printLog(t)}r.send(t.data||null)},this.xhr=function(e){return e?void 0!==window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?new XMLHttpRequest:null:void 0!==window.XMLHttpRequest?new XMLHttpRequest:null},this.getUA=function(){var e,t={},n=navigator.userAgent.toLowerCase();return(e=n.match(/opera.([\d.]+)/))?t.opera=Number(e[1].split(".")[0]):(e=n.match(/msie ([\d.]+)/))?t.ie=Number(e[1].split(".")[0]):(e=n.match(/edge.([\d.]+)/))?t.edge=Number(e[1].split(".")[0]):(e=n.match(/firefox\/([\d.]+)/))?t.firefox=Number(e[1].split(".")[0]):(e=n.match(/chrome\/([\d.]+)/))?t.chrome=Number(e[1].split(".")[0]):(e=n.match(/version\/([\d.]+).*safari/))?t.safari=Number(e[1].match(/^\d*.\d*/)):(e=n.match(/trident\/([\d.]+)/))&&(t.ie=11),t},this.isSupportBeaconSend=function(){var t=!1;if("object"!=typeof navigator||"function"!=typeof navigator.sendBeacon)return t;var n=e.getUA(),r=navigator.userAgent.toLowerCase();if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){var i=(r.match(/os [\d._]*/gi)+"").replace(/[^0-9|_.]/gi,"").replace(/_/gi,".").split(".");void 0===n.safari&&(n.safari=i[0]),i[0]&&+i[0]<13?(n.chrome>41||n.firefox>30||n.opera>25||n.safari>12)&&(t=!0):(n.chrome>41||n.firefox>30||n.opera>25||n.safari>11.3)&&(t=!0)}else(n.chrome>38||n.edge>13||n.firefox>30||n.opera>25||n.safari>11)&&(t=!0);return t},this.sendBeacon=function(t){return!0===e.isSupportBeaconSend()?navigator.sendBeacon(t.url,new URLSearchParams(JSON.stringify(t.data||{})))?Promise.resolve({success:!0}):Promise.reject({success:!1}):Promise.reject({message:"不支持sendBeacon,发送失败!",success:!1})}}return e.prototype.printLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(this.isObject(e[0])&&(e[0]=this.formatJsonString(e[0])),"object"==typeof console&&console.log)try{return console.log.apply(console,e)}catch(t){console.log(e[0])}},e.prototype.isObject=function(e){return null!=e&&"[object Object]"==toString.call(e)},e.prototype.isUndefined=function(e){return void 0===e},e.prototype.isString=function(e){return"[object String]"==toString.call(e)},e.prototype.isDate=function(e){return"[object Date]"==toString.call(e)},e.prototype.isBoolean=function(e){return"[object Boolean]"==toString.call(e)},e.prototype.isNumber=function(e){return"[object Number]"==toString.call(e)&&/[\d\.]+/.test(String(e))},e.prototype.isElement=function(e){return!(!e||1!==e.nodeType)},e.prototype.isFunction=function(e){if(!e)return!1;var t=toString.call(e);return"[object Function]"==t||"[object AsyncFunction]"==t},e.prototype.isJSONString=function(e){try{JSON.parse(e)}catch(e){return!1}return!0},e.prototype._decodeURIComponent=function(e){var t=e;try{t=decodeURIComponent(e)}catch(n){t=e}return t},e.prototype.getMainHost=function(){var e="mh_"+Math.random(),t=new RegExp("(^|;)\\s*"+e+"=12345"),n=new Date(0),r=document.domain.split("."),i=[];for(i.unshift(r.pop());r.length;){i.unshift(r.pop());var o=i.join("."),a=e+"=12345;domain=."+o;if(document.cookie=a,t.test(document.cookie))return document.cookie=a+";expires="+n,o}},e}()));export default n;
|
|
16
16
|
//# sourceMappingURL=index.esm.js.map
|