@fle-sdk/event-tracking-web 1.0.8 → 1.1.2-alpha.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 CHANGED
@@ -1,10 +1,18 @@
1
1
  # @fle.sdk/event-tracking-web
2
+ > **构建用户数据体系,让用户行为数据发挥深远的价值。**
2
3
 
3
- > 前端数据埋点 sdk(web)
4
4
 
5
- ## Install
5
+ ## 前言
6
+ **WEB数据埋点sdk,开始之前请确保了解埋点的架构和基础知识**
7
+ > 埋点中比较重要的组成部分就是每个事件的 key,注意的是 key 至少由两部分组成。
8
+ > 完整的 key 由这几部分组成:appkey.pagekey.partkey 通过“.”来分割
6
9
 
7
- ```js
10
+ - appkey:APP应用唯一标识
11
+ - pagekey:页面唯一标识,默认取当前路由
12
+ - partkey:控件/自定义事件唯一标识,可通过接口获取或自定义
13
+
14
+ ## 一、下载
15
+ ```jsx
8
16
  // npm
9
17
  npm install @fle-sdk/event-tracking-web --save-dev
10
18
 
@@ -12,154 +20,339 @@ npm install @fle-sdk/event-tracking-web --save-dev
12
20
  yarn add @fle-sdk/event-tracking-web
13
21
  ```
14
22
 
15
- ## Brief Introduction
16
-
17
- > 埋点中比较重要的组成部分就是每个事件的 key,注意的是 key 至少由两部分组成。完整的 key 由这几部分组成:appkey.pagekey.partkey 通过“.”来分割
18
-
19
- - appkey:应用唯一标识
20
- - pagekey:页面唯一标识,取当前路由 window.location.pathname.replace(/\//g, '\_').substr(1)
21
- - partkey:控件/自定义事件的唯一标识,当是控件触发且没有 partkey 时,会取当前控件的 id/class/dom
22
-
23
- #### Tracking
24
-
25
- > 初始化 sdk 后,sdk 会对应用进行事件监听,进行自动上报,主要监听以下几个事件
23
+ ## 二、全埋点
24
+ > 全埋点包括三种事件:Web 页面浏览、Web 元素点击、Web 页面留存时长,对应的配置如下:
25
+
26
+ ```jsx
27
+ // 初始化
28
+ WebTracking.init({
29
+ appKey: "218844",
30
+ showLog: true,
31
+ autoTrack: true, // 设置该属性之后,SDK 就会自动收集页面浏览事件
32
+ isTrackSinglePage: true,
33
+ contentType: "application/json",
34
+ serverUrl: "https://xxx/push",
35
+ });
36
+ ```
37
+ ###
38
+ ### 2.1 元素点击
39
+ > 元素的点击事件上报 attr 属性中必须含有 **data-part-key** ,否则会被过滤。
26
40
 
27
- - load(页面初始化)
28
- - beforeunload(页面卸载)
29
- - pushState(追加新路由)
30
- - replaceState(替换当前路由)
31
- - popstate(前进、回退、hash 值改变)
32
- - hashchange(hash 值改变)
33
- - click(点击事件,这个要单独拎出去补充)
41
+ ```jsx
42
+ // 对充值按钮的点击次数进行统计
43
+ <button data-part-key="recharge_btn" data-desc="显示充值弹窗">
44
+ 充值
45
+ </button>
46
+ ```
34
47
 
35
- #### Params
36
48
 
37
- > 上报参数示例
49
+ ### 2.2 全埋点参数示例
50
+ > 全埋点三种类型的上报参数示例,建议都了解一下
38
51
 
39
52
  ```json
40
53
  {
54
+ "desc": "Web 浏览页面",
55
+ "event": "PageView",
41
56
  "appKey": "218844",
42
- "pageKey": "goods_detail",
43
57
  "siteId": "",
44
- "event": "load",
45
- "desc": "浏览器上报事件:页面加载",
46
- "itemKey": "218844.goods_detail",
47
- "requestTime": 1627377493049,
48
- "deviceId": "c12918a5b139734a78fab0843c62ff51",
58
+ "itemKey": "218844.app_other",
59
+ "requestTime": 1638456820316,
60
+ "deviceId": "f9e3f35a6371f369a2c9f21c48dcabe8",
49
61
  "privateParamMap": {
50
- "sourceUrl": "/app/other",
51
- "sdkVersion": "1.0.6",
52
- "platformType": "pc",
53
- "system": {
62
+ "currentUrl": "http://localhost:9999/app/other",
63
+ "targetUrl": null,
64
+ "sdkVersion": "1.1.0",
65
+ "pageWidth": 742,
66
+ "pageHeight": 867,
67
+ "screenWidth": 1680,
68
+ "screenHeight": 1050,
69
+ "systemsInfo": {
54
70
  "language": "zh-CN",
55
- "location": "https://xxx/goods/detail?goodsId=1000139",
71
+ "platform": "pc",
56
72
  "client": "Mac, MacOS 10.15.7",
57
- "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
58
- "navigationStart": 1627377492850,
59
- "navigation": "6ms",
60
- "dns": "12ms",
61
- "tcp": "30ms",
62
- "request": "300ms",
63
- "response": "8ms"
73
+ "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36",
74
+ "navigationStart": 1638456820099,
75
+ "navigation": "1ms",
76
+ "dns": "0ms",
77
+ "tcp": "0ms",
78
+ "request": "2ms",
79
+ "response": "1ms"
64
80
  },
65
- "urlParams": {
66
- "goodsId": 1000139
81
+ "urlParams": {},
82
+ "userInfo": {
83
+ "userId": 20211232232123
67
84
  }
68
85
  }
69
86
  }
70
- ```
71
87
 
72
- #### Click
73
-
74
- > 监听点击事件上报是有条件的,并不是所有的点击事件都会上报,只有 attr 属性中含有 <b>data-part-key</b> 的控件所触发的事件才会上报。
88
+ {
89
+ "desc": "Web 元素点击",
90
+ "event": "WebClick",
91
+ "appKey": "218844",
92
+ "siteId": "",
93
+ "itemKey": "218844.main.8ydgk",
94
+ "requestTime": 1638460476808,
95
+ "deviceId": "f9e3f35a6371f369a2c9f21c48dcabe8",
96
+ "privateParamMap": {
97
+ "position": [
98
+ 126,
99
+ 87
100
+ ],
101
+ "targetEle": {
102
+ "id": "",
103
+ "nodeName": "H1",
104
+ "className": ""
105
+ },
106
+ "pointerType": "mouse",
107
+ "currentUrl": "http://localhost:9999/main?a=1",
108
+ "elementSelector": "#root > div:nth-of-type(1) > div:nth-of-type(1) > h1:nth-of-type(1)",
109
+ "sdkVersion": "1.1.0",
110
+ "pageWidth": 742,
111
+ "pageHeight": 867,
112
+ "screenWidth": 1680,
113
+ "screenHeight": 1050,
114
+ "systemsInfo": {
115
+ "language": "zh-CN",
116
+ "platform": "pc",
117
+ "client": "Mac, MacOS 10.15.7",
118
+ "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36",
119
+ "navigationStart": 1638456820099,
120
+ "navigation": "1ms",
121
+ "dns": "0ms",
122
+ "tcp": "0ms",
123
+ "request": "2ms",
124
+ "response": "1ms",
125
+ "domComplete (domLoaded)": "201ms (186ms)",
126
+ "loadEvent": "1ms",
127
+ "total (DOM)": "218ms (217ms)"
128
+ },
129
+ "urlParams": {
130
+ "a": "1"
131
+ },
132
+ "userInfo": {
133
+ "userId": 20211232232123
134
+ }
135
+ }
136
+ }
75
137
 
76
- ```js
77
- // 对充值按钮的点击次数进行统计
78
- <button data-part-key="recharge_btn" data-desc="显示充值弹窗">
79
- 充值
80
- </button>
138
+ {
139
+ "desc": "Web 页面浏览时长",
140
+ "event": "PageRetained",
141
+ "appKey": "218844",
142
+ "siteId": "",
143
+ "itemKey": "218844.app_other",
144
+ "requestTime": 1638460554657,
145
+ "deviceId": "f9e3f35a6371f369a2c9f21c48dcabe8",
146
+ "privateParamMap": {
147
+ "sdkVersion": "1.1.0",
148
+ "pageWidth": 742,
149
+ "pageHeight": 867,
150
+ "screenWidth": 1680,
151
+ "screenHeight": 1050,
152
+ "currentUrl": "http://localhost:9999/app/other",
153
+ "systemsInfo": {
154
+ "language": "zh-CN",
155
+ "platform": "pc",
156
+ "client": "Mac, MacOS 10.15.7",
157
+ "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36",
158
+ "navigationStart": 1638456820099,
159
+ "navigation": "1ms",
160
+ "dns": "0ms",
161
+ "tcp": "0ms",
162
+ "request": "2ms",
163
+ "response": "1ms",
164
+ "domComplete (domLoaded)": "201ms (186ms)",
165
+ "loadEvent": "1ms",
166
+ "total (DOM)": "218ms (217ms)"
167
+ },
168
+ "urlParams": {},
169
+ "userInfo": {
170
+ "userId": 20211232232123
171
+ }
172
+ },
173
+ "retainedStartTime": 1638460451953
174
+ }
81
175
  ```
82
176
 
177
+
83
178
  ---
84
179
 
85
- ## API
86
180
 
87
- > 主要用到的两个函数,一个是初始化时调用,一个在手动业务埋点时调用。
181
+ ## 三、API
182
+ WebTracking
88
183
 
89
- - WebTracking.init() ---初始化 sdk
90
- - WebTracking.tracking() ---手动上报
184
+ - init() ---初始化
185
+ - preset() ---配置全局参数(注意:如果配置的全局属性初始化已配置,将覆盖。)
186
+ - login() ---用户登录
187
+ - track() ---自定义代码埋点上报
188
+ - getDeviceId() ---获取设备唯一标识
91
189
 
92
- ### WebTracking.init
190
+ ### Init
191
+ #### 参数
192
+ | **参数名** | **type** | **描述** | **是否必填** | **默认值** |
193
+ | --- | --- | --- | --- | --- |
194
+ | appKey | string | 应用唯一标识(由接口生成) | 是 | - |
195
+ | serverUrl | string | 数据接收地址 | 是 | - |
196
+ | autoTrack | boolean | 是否开启全埋点(指的是:页面浏览、元素点击事件自动上报) | 否 | false |
197
+ | showLog | boolean | 是否在网页控制台打印发送的数据 | 否 | false |
198
+ | useClientTime | boolean | 是否使用客户端系统时间 | 否 | true |
199
+ | sendTimeout | number | 接口发送超时时长,超过该时长未发送成功将强制取消 | 否 | 3000 |
200
+ | isTrackSinglePage | boolean | 是否采集单页面应用的路由变化 | 否 | false |
201
+ | siteId | numberstring | 站点 Id | 否 | - |
202
+ | contentType | string | application/json
203
+ application/x-www-form-urlencoded | 否 | application/x-www-form-urlencoded |
93
204
 
94
- > sdk 初始化说明
95
205
 
96
- #### Params
206
+ #### 例子
207
+ > 初始化 sdk 例子,建议在 src/App.js 中初始化,且需在**useLayoutEffect**中初始化。
97
208
 
98
- > sdk 初始化时的参数
209
+ ```jsx
210
+ import React, { useLayoutEffect } from "react";
211
+ import WebTracking from "@fle-sdk/event-tracking-web";
99
212
 
100
- | 参数名 | type | 描述 | 是否必填 | 默认值 |
101
- | ---------- | ------------- | ----------------------------- | -------- | ------ |
102
- | appKey | string | 应用唯一标识(由接口生成) | 是 | - |
103
- | serverApi | string | 接口名 | 是 | - |
104
- | serverHost | string | 服务端 host | 是 | - |
105
- | userId | number/string | 用户 Id,无则根据设备 Id 区分 | 否 | - |
106
- | siteId | number/string | 站点 Id | 否 | - |
213
+ const App = () => {
214
+ useLayoutEffect(() => {
215
+ // init tracking
216
+ WebTracking.init({
217
+ appKey: "xxxxxx", // 由接口生成,应用唯一标识
218
+ serverUrl: "https://www.serverHost.com/serverApi/push",
219
+ autoTrack: true,
220
+ showLog: true,
221
+ isTrackSinglePage: true
222
+ });
223
+ }, []);
107
224
 
108
- #### Example
225
+ return <div className="App"></div>;
226
+ };
109
227
 
110
- > 初始化 sdk 例子,建议在 src/App.js 中初始化,且需在<b>useLayoutEffect</b>中初始化。
228
+ export default App;
229
+ ```
111
230
 
112
- ```js
231
+ ### Preset
232
+ > 除了不可配置appKey、serverUrl,本质上和init差不多,这么做是为了更好的区分使用场景,不产生歧义。
233
+
234
+ #### 参数
235
+ | **参数名** | **type** | **描述** | **是否必填** | **默认值** |
236
+ | --- | --- | --- | --- | --- |
237
+ | autoTrack | boolean | 是否开启全埋点(指的是:页面浏览、元素点击事件自动上报) | 否 | false |
238
+ | showLog | boolean | 是否在网页控制台打印发送的数据 | 否 | false |
239
+ | useClientTime | boolean | 是否使用客户端系统时间 | 否 | true |
240
+ | sendTimeout | number | 接口发送超时时长,超过该时长未发送成功将强制取消 | 否 | 3000 |
241
+ | isTrackSinglePage | boolean | 是否采集单页面应用的路由变化 | 否 | false |
242
+ | siteId | numberstring | 站点 Id | 否 | - |
243
+
244
+ #### 例子
245
+ ```jsx
113
246
  import React, { useLayoutEffect } from "react";
114
- import WebTracking from "@fle-sdk/event-tracking-web/lib/index.ems";
247
+ import WebTracking from "@fle-sdk/event-tracking-web";
115
248
 
116
249
  const App = () => {
117
250
  useLayoutEffect(() => {
118
251
  // init tracking
119
252
  WebTracking.init({
120
- appKey: "xxx", // 由接口生成,应用唯一标识
121
- serverApi: "/serverApi/push",
122
- serverHost: "https://www.serverHost.com",
253
+ appKey: "xxxxxx", // 由接口生成,应用唯一标识
254
+ serverUrl: "https://www.serverHost.com/serverApi/push",
123
255
  });
256
+
257
+ // 配置全局参数,初始化后预置属性用该方法。
258
+ // 注意:如果配置的全局属性初始化已配置,将覆盖
259
+ WebTracking.preset({
260
+ autoTrack: true,
261
+ showLog: true,
262
+ isTrackSinglePage: true,
263
+ sendTimeout: 10000
264
+ })
124
265
  }, []);
266
+
267
+ const pageHandle = () => {
268
+ WebTracking.preset({
269
+ autoTrack: false, // 关闭全埋点
270
+ })
271
+ }
125
272
 
126
- return <div className="App"></div>;
273
+ return <div className="App" onClick={pageHandle}></div>;
127
274
  };
128
275
 
129
276
  export default App;
130
277
  ```
131
278
 
132
- ## WebTracking.tracking
279
+ ### Login
280
+ #### 参数
281
+ | 参数名 | type | 描述 | 是否必填 | 默认值 |
282
+ | --- | --- | --- | --- | --- |
283
+ | userId | numberstring | 用户ID | 否 | - |
284
+
285
+ #### 例子
286
+ ```jsx
287
+ import React, { useEffect } from "react";
288
+ import WebTracking from "@fle-sdk/event-tracking-web";
289
+ import { LoginStore } from "store";
290
+
291
+ const Test = () => {
292
+ const getUserInfo = () => {
293
+ const { userId } = await LoginStore.getUserInfo();
294
+ WebTracking.Login("用户ID");
295
+ }
296
+ useEffect(() => {
297
+ getUserInfo()
298
+ }, []);
299
+
300
+ return <div className="Test"></div>;
301
+ };
302
+
303
+ export default Test;
304
+ ```
305
+
133
306
 
134
- #### Params
307
+ ### GetDeviceId
308
+ #### 例子
309
+ > 获取设备唯一标识,单用户没有登录时即用户唯一标识
135
310
 
136
- > 手动上报时的参数
311
+ ```jsx
312
+ import React, { useEffect } from "react";
313
+ import WebTracking from "@fle-sdk/event-tracking-web";
314
+ import { LoginStore } from "store";
137
315
 
138
- | 参数名 | type | 描述 | 是否必填 | 默认值 |
139
- | -------- | ------ | ------------------------------------------------------------------------------- | -------- | -------------- |
140
- | partkey | string | 上报事件 Key(由前端自定义,该应用下需唯一且具有一定意义,例:goods_detail_pv) | 是 | - |
141
- | desc | string | 上报事件描述 | 否 | 自定义上报事件 |
142
- | business | object | 上报事件业务参数 | 否 | - |
316
+ const Test = () => {
317
+ useEffect(() => {
318
+ WebTracking.getDeviceId();
319
+ }, []);
143
320
 
144
- #### Example
321
+ return <div className="Test"></div>;
322
+ };
323
+
324
+ export default Test;
325
+ ```
326
+
327
+
328
+ ### Track
329
+ > 手动代码埋点上报
145
330
 
146
- > 手动上报例子
331
+ #### 上报参数
332
+ | **参数名** | **type** | **描述** | **是否必填** | **默认值** |
333
+ | --- | --- | --- | --- | --- |
334
+ | partkey | numberstring | 上报事件 Key(由前后端协商定义或由后端接口生成,该应用下需唯一且具有一定意义,例:goods_detail_pv) | 是 | - |
335
+ | desc | string | 上报事件描述 | 否 | 自定义上报事件 |
336
+ | business | object | 上报的业务参数 | 否 | - |
147
337
 
148
- ```js
338
+
339
+ #### 例子
340
+ ```jsx
149
341
  import React, { useEffect } from "react";
150
- import WebTracking from "@fle-sdk/event-tracking-web/lib/index.ems";
342
+ import WebTracking from "@fle-sdk/event-tracking-web";
151
343
 
152
344
  const Index = () => {
153
345
  const history = useHistory();
154
346
 
155
- const tracking = () =>
156
- WebTracking.tracking({ desc: "我是描述", partkey: "xxx" })
157
- .then((res) => alert(res.message || "上报成功!"))
158
- .catch((err) => alert(err.message || "上报失败!"));
347
+ const tracking = () => {
348
+ WebTracking.track({ desc: "我是描述", partkey: "xxx" })
349
+ .then((res) => console.log(res || "上报成功!"))
350
+ .catch((err) => console.log(err || "上报失败!"));
351
+ }
159
352
 
160
353
  // 手动上报商品详情浏览量示例
161
354
  useEffect(() => {
162
- WebTracking.tracking({
355
+ WebTracking.track({
163
356
  desc: "商品详情PV埋点",
164
357
  partkey: "goods_detail_pv",
165
358
  business: {
@@ -178,3 +371,62 @@ const Index = () => {
178
371
 
179
372
  export default Index;
180
373
  ```
374
+
375
+ ## 四、完整参数明细
376
+ ### 4.1 request参数明细
377
+ | **参数名** | **type** | **描述** | **示例值** |
378
+ | --- | --- | --- | --- |
379
+ | appKey | string | 应用唯一标识(由接口生成) | - |
380
+ | event | string | 有四种类型的值:
381
+ PageViewPageRetainedCustomTrackWebClick | - |
382
+ | itemKey | string | 当前埋点事件Key | appkey.pagekey.partkey |
383
+ | serverUrl | string | 数据接收地址 | - |
384
+ | siteId | numberstring | 站点 ID | - |
385
+ | showLog | boolean | 是否在网页控制台打印发送的数据 | false |
386
+ | platform | string | 应用平台类型,如不传会自动获取
387
+ 可选值:h5pc | - |
388
+ | autoTrack | boolean | 是否开启全埋点 指的是:页面浏览、元素点击事件自动上报 | true |
389
+ | useClientTime | boolean | (是否使用客户端系统时间)注意:客户端系统时间可能会不准确,导致该字段不准确 | true |
390
+ | requestTime | number | 发送请求事件 | - |
391
+ | sendTimeout | number | 接口发送超时时长,超过该时长未发送成功将强制取消,单位:毫秒 | 3000 |
392
+ | isTrackSinglePage | boolean | 是否采集单页面应用的路由变化 | false |
393
+ | contentType | string | 可选值:
394
+ application/json
395
+ application/x-www-form-urlencoded | application/x-www-form-urlencoded |
396
+ | privateParamMap | object | 私有参数 | [查看详情](#mWMBL) |
397
+
398
+ #### 4.2.1 privateParamMap参数明细
399
+ | **参数名** | **type** | **描述** | **示例值** |
400
+ | --- | --- | --- | --- |
401
+ | currentUrl | string | 当前URL | http://localhost:9999/main |
402
+ | targetUrl | string | 目标URL | http://localhost:9999/app/other |
403
+ | business | {[key: string]: any} | 手动埋点参数 | - |
404
+ | targetEle | TargetEleProps | 触发元素属性 | [查看详情](#YC74u) |
405
+ | pageWidth | number | 页面可视区宽度 | 1440 |
406
+ | pageHeight | number | 页面可视区高度 | 860 |
407
+ | screenWidth | number | 显示屏宽度 | 1440 |
408
+ | screenHeight | number | 显示屏高度 | 860 |
409
+ | pointerType | string | 手动触发的指针类型 | mouse、touch、pen |
410
+ | elementSelector | string | 触发元素链路 | #root > div:nth-of-type(1) > div:nth-of-type(1) > h1:nth-of-type(1) |
411
+ | userInfo | {[key: string]: any} | 用户信息 | {userName: "啊盛", userId: 1001} |
412
+ | urlParams | string | 路由参数 | - |
413
+ | systemsInfo | SystemsInfoTypes | 系统信息 | [查看详情](#VHfQH) |
414
+ | sdkVersion | string | 埋点SDk版本 | 1.0.0 |
415
+ | retainedDuration | number | 页面停留时长(毫秒) | 2000 |
416
+
417
+ #### 4.2.2 TargetEleProps参数明细
418
+ | **参数名** | **type** | **描述** | **示例值** |
419
+ | --- | --- | --- | --- |
420
+ | nodeName | string | dom节点名称 | BUTTON |
421
+ | id | string | id类名 | main_btn |
422
+ | className | string | class类名 | fx-primary-btn |
423
+ | position | [number, number] | 元素触发位置:[x, y] | [100, 200] |
424
+
425
+ #### 4.2.3 SystemsInfoTypes参数明细
426
+ | **参数名** | **type** | **描述** | **示例值** |
427
+ | --- | --- | --- | --- |
428
+ | language | string | 系统语言 | zh-CN |
429
+ | network | string | 网络类型 | - |
430
+ | 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 |
431
+ | client | string | 客户端(Mac/Android/iPhone/iPad/iPod/WeChat) | Mac, MacOS 10.15.7 |
432
+
package/lib/index.ems.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(){return(e=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},t=new(function(){function t(){var t=this;this.init=function(e){if(e instanceof Object)for(var n in e)void 0!==t.config[n]&&(t.config[n]=e[n]),void 0!==t.otherInfo[n]&&(t.otherInfo[n]=e[n]),void 0!==t.apiConfig[n]&&(t.apiConfig[n]=e[n]);t.config.pageKey=window.location.pathname.replace(/\//g,"_").substr(1),t.otherInfo.platformType=t.getPlatformType(),t.otherInfo.system=t.systemInfo(),t.currentUrl=window.location.pathname,t.rewriteHistory(),t.listener()},this.tracking=function(e){var n=e.desc,o=e.partkey,a=e.business;return t.trackingPost({event:"customTrack",desc:n||t.eventDescMap.customTrack,itemKey:t.getItemKey(o||"customTrack"),extroInfo:{business:a}})},this.trackingPost=function(n){var o=n.event,a=n.desc,i=n.itemKey,r=n.extroInfo,s=e(e({},t.config),{event:o,desc:a,itemKey:i,requestTime:t.getTimeStamp(),deviceId:t.getDistinctId(),privateParamMap:e(e(e({},r),t.otherInfo),{urlParams:t.getQueryValue()})}),c={url:""+t.apiConfig.serverHost+t.apiConfig.serverApi,headers:{"Content-Type":"application/json"},params:JSON.stringify(s)};if(["beforeunload","pushState","replaceState","hashchange","popstate"].indexOf(o)>=0){var d=t.getCookie("retainedStartTime"),u=d?+d:t.getTimeStamp(),p={url:""+t.apiConfig.serverHost+t.apiConfig.serverApi,headers:{"Content-Type":"application/json"},params:JSON.stringify(e(e({},s),{event:"retained",desc:t.eventDescMap.retained,retainedStartTime:u}))};"beforeunload"===o?t.sendBeacon(p):t.httpPost(p),t.setCookie("retainedStartTime",t.getTimeStamp())}return"beforeunload"===o?t.sendBeacon(c):t.httpPost(c)},this.onClick=function(e){if(e.target.dataset.partKey){var n=[e.pageX,e.pageY],o=e.target.id,a=e.target.className,i={nodeName:e.target.nodeName,id:o,className:a},r=document.documentElement.offsetWidth,s=document.documentElement.offsetHeight,c=window.screen.width,d=window.screen.height,u=window.screen.availWidth,p=window.screen.availHeight,h=window.innerWidth,l=window.innerHeight;t.trackingPost({event:"click",desc:e.target.dataset.desc||t.eventDescMap.click,itemKey:t.getItemKey(e.target.dataset.partKey),extroInfo:{position:n,targetEle:i,pageWidth:r,pageHeight:s,screenWidth:c,screenHeight:d,screenAvailWidth:u,screenAvailHeight:p,windowInnerWidth:h,windowInnerHeight:l}})}},this.addRouteEvent=function(e){["load","beforeunload","pushState","replaceState",window.history.pushState?"popstate":"hashchange"].forEach((function(n){t.addEventListener(window,n,e)}))},this.onPushStateHandler=function(e){var n;t.trackingPost({event:e.type,desc:t.eventDescMap[e.type],itemKey:t.getItemKey(),extroInfo:{sourceUrl:t.currentUrl,targetUrl:null===(n=e.arguments)||void 0===n?void 0:n[2]}}),["load"].indexOf(e.type)>=0&&t.setCookie("retainedStartTime",t.getTimeStamp()),t.currentUrl=window.location.pathname,t.config.pageKey=window.location.pathname.replace(/\//g,"_").substr(1)},this.listener=function(){t.addRouteEvent(t.onPushStateHandler),t.addEventListener(window,"click",t.onClick),t.addEventListener(window,"unload",t.unload)},this.unload=function(){["load","beforeunload","pushState","replaceState",window.history.pushState?"popstate":"hashchange"].forEach((function(e){t.removeEventListener(window,e,t.onPushStateHandler)})),t.removeEventListener(window,"click",t.onClick),t.removeEventListener(window,"unload",t.unload)},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.getItemKey=function(e){var n=t.config;return[n.appKey,n.pageKey,e].filter((function(e){return!!e})).reduce((function(e,t){return e+(e.length?".":"")+t}),"")},this.getQueryValue=function(e){for(var t=decodeURI(window.location.search.substring(1)).split("&"),n={},o=0;o<t.length;o++){var a=t[o].split("=");if(a[0]===e)return a[1];n[a[0]]=a[1]}return e?null:n},this.getTimeStamp=function(){return(new Date).getTime()},this.getDistinctId=function(){var e=t.getCookie("distinctId");return e||(e=t.uuid(),t.setCookie("distinctId",e),e)},this.getPlatformType=function(){for(var e=navigator.userAgent,t=new Array("Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"),n=!0,o=0;o<t.length;o++)if(e.indexOf(t[o])>0){n=!1;break}return n?"pc":"h5"},this.setCookie=function(e,t){document.cookie=e+"="+t+";"+document.cookie},this.getCookie=function(e){e+="=";for(var t=decodeURIComponent(document.cookie).split(";"),n=0;n<t.length;n++){for(var o=t[n];" "===o.charAt(0);)o=o.substring(1);if(0===o.indexOf(e))return o.substring(e.length,o.length)}return""},this.httpPost=function(e){var t=e.url,n=e.headers,o=e.params,a=e.async,i=void 0===a||a;return new Promise((function(e,a){var r=new XMLHttpRequest;r.open("post",t,i),r.onreadystatechange=function(){if(4===r.readyState){if(200===r.status){var t=r.responseText;if(!t)return a({message:"Request Error"});var n=null;try{n=JSON.parse(t)}catch(e){}return n&&"2000"===n.code?e(n):a({message:"Request Error"})}return console.log(r.statusText),a({message:r.statusText})}},r.onerror=function(e){return console.log(r.statusText),a({message:r.statusText})},n instanceof Object&&Object.keys(n).forEach((function(e){r.setRequestHeader(e,n[e])})),r.send(o)}))},this.sendBeacon=function(n){if("object"==typeof navigator&&"function"==typeof navigator.sendBeacon){var o=new Blob([JSON.stringify(n.params)],{type:"application/json"});return navigator.sendBeacon(n.url,o),Promise.resolve({message:"发送成功!"})}return t.httpPost(e(e({},n),{async:!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.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.rewriteHistory=function(){var e=window.history,t=function(e){var t=window.history,n=t[e],o=new Event(e);return function(){var e=n.apply(t,arguments);return o.arguments=arguments,window.dispatchEvent(o),e}};window.history.pushState&&(e.pushState=t("pushState"),e.replaceState=t("replaceState"))},this.config={appKey:"",pageKey:"",siteId:""},this.otherInfo={sdkVersion:"1.0.7",platformType:"pc"},this.currentUrl="",this.apiConfig={serverApi:"",serverHost:""},this.eventDescMap={load:"浏览器上报事件:页面加载",beforeunload:"浏览器上报事件:页面卸载",pushState:"浏览器上报事件:追加新路由",replaceState:"浏览器上报事件:替换当前路由为新路由",popstate:"浏览器上报事件:前进、回退、hash值改变",hashchange:"浏览器上报事件:hash值改变",click:"点击上报事件",retained:"浏览器上报事件:留存时长",customTrack:"自定义事件上报"}}return t.prototype.systemInfo=function(){var e=navigator.userAgent,t=[],n={language:navigator.language},o=e.match(/MicroMessenger\/([\d\.]+)/i),a=o&&o[1]?o[1]:null;"servicewechat.com"===location.host||(n.location=location.href);var i=e.match(/(ipod).*\s([\d_]+)/i),r=e.match(/(ipad).*\s([\d_]+)/i),s=e.match(/(iphone)\sos\s([\d_]+)/i),c=e.match(/(android)\s([\d\.]+)/i),d=e.match(/(Mac OS X)\s([\d_]+)/i);t=[],c?t.push("Android "+c[2]):s?t.push("iPhone, iOS "+s[2].replace(/_/g,".")):r?t.push("iPad, iOS "+r[2].replace(/_/g,".")):i?t.push("iPod, iOS "+i[2].replace(/_/g,".")):d&&t.push("Mac, MacOS "+d[2].replace(/_/g,".")),a&&t.push("WeChat "+a),n.client=t.length?t.join(", "):"Unknown";var u=e.toLowerCase().match(/ nettype\/([^ ]+)/g);return u&&u[0]&&(t=[(u=u[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},t}());export default t;
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;
16
16
  //# sourceMappingURL=index.ems.js.map