visual-buried-point-platform-uni 1.0.0-alpha → 1.0.0-alpha.10
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 +160 -58
- package/index.js +48 -52
- package/lsi-md5.js +4 -5
- package/package.json +2 -2
- package/tools.js +57 -68
package/README.md
CHANGED
|
@@ -1,93 +1,195 @@
|
|
|
1
|
-
|
|
1
|
+
## Uni版自定义埋点SDK集成文档
|
|
2
2
|
|
|
3
|
+
### SDK更新日志
|
|
4
|
+
- 1.0.0-alpha.07 最新uni、终端通用埋点sdk;
|
|
5
|
+
- 1.0.0-alpha.08 自定义上报数据结构删除path字段;
|
|
3
6
|
|
|
7
|
+
### 1、引入方式
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
```js
|
|
10
|
+
//内网npm链接:http://verdaccio.gogdev.cn/
|
|
11
|
+
npm install visual-buried-point-platform-uni
|
|
12
|
+
```
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
### 2、初始化方式
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { init } from 'visual-buried-point-platform-uni'
|
|
18
|
+
onLaunch: function() {
|
|
19
|
+
//初始化sdk
|
|
20
|
+
init({
|
|
21
|
+
env: 'test', //环境变量 test production
|
|
22
|
+
token: '3212414516342554624', //热果平台-可视化埋点管理端-创建对应的项目生成.
|
|
23
|
+
sourceDomain: 'com.gzdzswy.onetravel', // 非必填,访问来源域名,取优先级:单次调用上报值 > 全局初始化值
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
```
|
|
10
28
|
|
|
11
|
-
|
|
29
|
+
### 3、设置绑定用户ID
|
|
12
30
|
|
|
13
|
-
-
|
|
14
|
-
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
31
|
+
- sdk初始化后,可通过 ***setUserId()*** 方法关联用户,sdk会默认生成一个游客ID
|
|
15
32
|
|
|
33
|
+
```js
|
|
34
|
+
// 应用在注册或登录成功后,可调用下面API设置用户ID,后续产生的统计事件将会与该用户关联起来
|
|
35
|
+
setUserId("登录成功-用户ID")
|
|
16
36
|
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
|
|
38
|
+
**示例:**
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { setUserId } from 'visual-buried-point-platform-uni'
|
|
42
|
+
setUserId(123456);
|
|
21
43
|
```
|
|
22
44
|
|
|
23
|
-
|
|
45
|
+
**注:为保持数据统计精确,在退出登录的时候建议调用一次清空:**
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
setUserId("");
|
|
49
|
+
```
|
|
24
50
|
|
|
25
|
-
|
|
51
|
+
### 4、自定义事件上报
|
|
26
52
|
|
|
27
|
-
|
|
53
|
+
- sdk初始化后,可通过 ***setCustomEvent()*** 方法上报自定义埋点事件,并为事件添加属性值:
|
|
28
54
|
|
|
29
|
-
|
|
30
|
-
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
-
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
-
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
-
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
55
|
+
#### 4.1 事件类型:
|
|
34
56
|
|
|
35
|
-
|
|
57
|
+
- 仅能选择埋点提供的事件类型,各事件类型的触发、上报由各业务平台埋点自行确认。事件类型如下:
|
|
58
|
+
- **搜索事件【 search 】**
|
|
59
|
+
- **动作事件【 action 】**
|
|
60
|
+
- **点击事件【 click 】**
|
|
61
|
+
- **浏览事件【 browse 】**
|
|
36
62
|
|
|
37
|
-
|
|
63
|
+
```js
|
|
64
|
+
// 调用自定义上报
|
|
65
|
+
setCustomEvent(data)
|
|
66
|
+
```
|
|
38
67
|
|
|
39
|
-
|
|
40
|
-
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
41
|
-
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
42
|
-
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
-
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
68
|
+
**配置:**
|
|
44
69
|
|
|
45
|
-
|
|
70
|
+
| 参数 | 必填 | 描述 |
|
|
71
|
+
| ------------- | ---- | ------------------------------ |
|
|
72
|
+
| $event_id | 是 | 对应创建的事件ID 【图2】 |
|
|
73
|
+
| $extend_param | 否 | 扩展字段,建议根据业务需求填上 |
|
|
74
|
+
| $busSegment | 否 | 业务板块 【表1】各自业务板块 |
|
|
75
|
+
| $module | 否 | 业务模块【表1】各自业务模块 |
|
|
46
76
|
|
|
47
|
-
|
|
77
|
+
表1
|
|
48
78
|
|
|
49
|
-
|
|
79
|
+
```js
|
|
80
|
+
示例如下:
|
|
81
|
+
业务板块 业务模块
|
|
82
|
+
busSegment module
|
|
83
|
+
1.景区/门票 1.门票
|
|
84
|
+
2.民宿/酒店 1.民宿 2.酒店
|
|
85
|
+
```
|
|
50
86
|
|
|
51
|
-
|
|
87
|
+
**示例:**
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
// 注:
|
|
92
|
+
data: JSON字符串
|
|
93
|
+
{
|
|
94
|
+
$event_id: 对应创建的事件ID 【必填字段】
|
|
95
|
+
$extend_param: 扩展参数(JSON字符串) 【非必填字段,建议根据业务需求填上】
|
|
96
|
+
$busSegment: 业务板块 【非必填字段,建议业务填上, 否则数据统计可能出现缺失】
|
|
97
|
+
$module: 业务模块 【非必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
|
|
98
|
+
$ctk: 渠道推广编码 【非必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
|
|
99
|
+
$duration: 停留时长 【非必填字段】
|
|
100
|
+
$event_code: 事件标识符 【必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
|
|
101
|
+
$page: 当前页对象 【非必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
|
|
102
|
+
$path: 埋点组件的路径 【必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
|
|
103
|
+
}
|
|
104
|
+
// 参考:【点击事件】
|
|
105
|
+
const params = {
|
|
106
|
+
$event_id: "3213106620739878912",
|
|
107
|
+
$busSegment: 1,
|
|
108
|
+
$module: 1,
|
|
109
|
+
$ctk: "",
|
|
110
|
+
$extend_param: {
|
|
111
|
+
title: "自定义[点击事件]上报-点击_密码登录按钮",
|
|
112
|
+
clickContent: "密码登录",
|
|
113
|
+
....
|
|
114
|
+
....
|
|
115
|
+
},
|
|
116
|
+
$event_code: "",
|
|
117
|
+
$page: {
|
|
118
|
+
domain: "",
|
|
119
|
+
path: "",
|
|
120
|
+
title: "",
|
|
121
|
+
},
|
|
122
|
+
$path: "",
|
|
123
|
+
}
|
|
124
|
+
setCustomEvent(params)
|
|
125
|
+
```
|
|
52
126
|
|
|
53
|
-
|
|
127
|
+
### 5、流量上报
|
|
128
|
+
|
|
129
|
+
- sdk初始化后,可通过**onStartTrack(params)** 方法注册上报流量,并为上报添加属性值:
|
|
130
|
+
|
|
131
|
+
**注册上报流量:onStartTrack(params)**
|
|
132
|
+
|
|
133
|
+
**配置:**【以下配置参数建议上报】
|
|
134
|
+
|
|
135
|
+
| 参数 | 必填 | 类型 | 描述 |
|
|
136
|
+
| ------------ | ---- | ------------------- | ---------------- |
|
|
137
|
+
| domain | 是 | string | 域名 |
|
|
138
|
+
| path | 是 | string | 路径 |
|
|
139
|
+
| circulation | 否 | number | 页面访问类型 |
|
|
140
|
+
| ctk | 否 | string | 渠道推广编码 |
|
|
141
|
+
| duration | 否 | number | 停留时长 |
|
|
142
|
+
| busSegment | 否 | string | 业务板块 【表1】 |
|
|
143
|
+
| module | 否 | string | 业务模块 【表1】 |
|
|
144
|
+
| extend_param | 否 | JSON对象 {} | 扩展参数 |
|
|
145
|
+
| sourceDomain | 否 | string | 访问来源域名 |
|
|
146
|
+
| sourceUrl | 否 | string | 访问来源url |
|
|
147
|
+
| title | 否 | string | 页面名称 |
|
|
148
|
+
| traceId | 否 | string | 追踪id |
|
|
149
|
+
| visitPage | 否 | number | 访问深度 |
|
|
150
|
+
| visitTime | 否 | yyyy-MM-dd HH:mm:ss | 访问时间 |
|
|
151
|
+
|
|
152
|
+
**示例:**
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
// 注:
|
|
156
|
+
data: JSON对象
|
|
157
|
+
const params = {
|
|
158
|
+
domain: "xxxx",
|
|
159
|
+
busSegment: 1,
|
|
160
|
+
module: 1,
|
|
161
|
+
title: "店铺详情",
|
|
162
|
+
sourceDomain: 'com.gzdzswy.onetravel',
|
|
163
|
+
extend_param: {
|
|
164
|
+
goods_id: 123456, //商品id 【根据业务确定】
|
|
165
|
+
store_id: 1111, //店铺id 【...】
|
|
166
|
+
business_id: 222, //商户id 【...】
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
onStartTrack(params)
|
|
170
|
+
```
|
|
54
171
|
|
|
55
|
-
|
|
56
|
-
Choose a self-explaining name for your project.
|
|
172
|
+
**销毁上报流量:调用onDestroyTrack()进行销毁**
|
|
57
173
|
|
|
58
|
-
|
|
59
|
-
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
174
|
+
**示例:**
|
|
60
175
|
|
|
61
|
-
|
|
62
|
-
|
|
176
|
+
```js
|
|
177
|
+
onDestroyTrack()
|
|
178
|
+
```
|
|
63
179
|
|
|
64
|
-
|
|
65
|
-
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
180
|
+
注: 上报数据是否成功可查看NetWork栏,调用流量上报 **track 接口** 和 自定义上报 **event 接口**的 response
|
|
66
181
|
|
|
67
|
-
|
|
68
|
-
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
182
|
+
#### 6、埋点后台管理系统
|
|
69
183
|
|
|
70
|
-
|
|
71
|
-
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
184
|
+
##### 云测管理端地址
|
|
72
185
|
|
|
73
|
-
|
|
74
|
-
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
186
|
+
- chameleon.gcongo.com.cn
|
|
75
187
|
|
|
76
|
-
|
|
77
|
-
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
188
|
+
#### 7、SDK 文档
|
|
78
189
|
|
|
79
|
-
|
|
80
|
-
State if you are open to contributions and what your requirements are for accepting them.
|
|
190
|
+
http://verdaccio.gogdev.cn/-/web/detail/visual-buried-point-platform-uni
|
|
81
191
|
|
|
82
|
-
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
83
192
|
|
|
84
|
-
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
85
193
|
|
|
86
|
-
## Authors and acknowledgment
|
|
87
|
-
Show your appreciation to those who have contributed to the project.
|
|
88
194
|
|
|
89
|
-
## License
|
|
90
|
-
For open source projects, say how it is licensed.
|
|
91
195
|
|
|
92
|
-
## Project status
|
|
93
|
-
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
package/index.js
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
getDeviceInfoError,
|
|
12
12
|
timeToStr,
|
|
13
13
|
getTrackObj,
|
|
14
|
+
getCurPath,
|
|
15
|
+
getUrl,
|
|
14
16
|
} from "./tools.js";
|
|
15
17
|
import { setReportUrl } from "./config.js";
|
|
16
18
|
|
|
@@ -29,6 +31,8 @@ let _config = {
|
|
|
29
31
|
srcDomain: "",
|
|
30
32
|
flushInterval: 15,
|
|
31
33
|
};
|
|
34
|
+
//custom
|
|
35
|
+
let timer = null;
|
|
32
36
|
//track upload interval
|
|
33
37
|
let tInterval = null;
|
|
34
38
|
let busObj = null;
|
|
@@ -43,7 +47,6 @@ export function init(config) {
|
|
|
43
47
|
let _cf = setReportUrl(config.env ? config.env : "");
|
|
44
48
|
reportUrl = _cf.reportUrl;
|
|
45
49
|
reportTrackUrl = _cf.reportTrackUrl;
|
|
46
|
-
eventListUrl = _cf.eventListUrl;
|
|
47
50
|
if (config.flushInterval) {
|
|
48
51
|
if (config.flushInterval < 5) {
|
|
49
52
|
config.flushInterval = 15;
|
|
@@ -75,14 +78,13 @@ export function init(config) {
|
|
|
75
78
|
startGlobalTime();
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
//the general custom
|
|
81
|
+
//the general custom reportCustom interval is enabled
|
|
79
82
|
function startGlobalTime() {
|
|
80
83
|
clearInterval(cInterval);
|
|
81
84
|
cInterval = setInterval(() => {
|
|
82
85
|
let cData = getSData();
|
|
83
|
-
console.log("storage data " + cData);
|
|
84
86
|
if (cData) {
|
|
85
|
-
|
|
87
|
+
reportCustom(cData);
|
|
86
88
|
delSData();
|
|
87
89
|
}
|
|
88
90
|
}, _config.flushInterval * 1000);
|
|
@@ -107,7 +109,7 @@ export function setCustomEvent(data) {
|
|
|
107
109
|
reportData = {
|
|
108
110
|
ctk: data.$ctk ? data.$ctk : "",
|
|
109
111
|
duration: "",
|
|
110
|
-
element: null,
|
|
112
|
+
element: data.$element ? data.$element : null,
|
|
111
113
|
eventId: data.$event_id ? data.$event_id : "",
|
|
112
114
|
event: data.$event_code ? data.$event_code : "",
|
|
113
115
|
groupId: "",
|
|
@@ -118,27 +120,29 @@ export function setCustomEvent(data) {
|
|
|
118
120
|
pageId: MD5(_path),
|
|
119
121
|
path: _path,
|
|
120
122
|
title: _page.title ? _page.title : "",
|
|
123
|
+
url: _path ? _path : getUrl(platform),
|
|
121
124
|
},
|
|
122
|
-
path: data.$path ? data.$path : "",
|
|
123
125
|
properties: data.$extend_param ? JSON.stringify(data.$extend_param) : "",
|
|
124
126
|
traceId: "",
|
|
125
127
|
trackId: trackId,
|
|
126
128
|
triggerTime: timeToStr(Date.now()),
|
|
127
|
-
url: "",
|
|
128
129
|
};
|
|
129
130
|
if (reportData) {
|
|
130
131
|
addCache(reportData);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
clearTimeout(timer);
|
|
133
|
+
timer = setTimeout(() => {
|
|
134
|
+
const data = getCache();
|
|
135
|
+
if (data.length) {
|
|
136
|
+
addSData(data);
|
|
137
|
+
clearCache();
|
|
138
|
+
}
|
|
139
|
+
}, 1000);
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
function
|
|
143
|
+
function reportCustom(data) {
|
|
140
144
|
if (!reportUrl) {
|
|
141
|
-
|
|
145
|
+
console.error("please set upload data reportUrl");
|
|
142
146
|
return;
|
|
143
147
|
}
|
|
144
148
|
const comData = commonData(data);
|
|
@@ -146,25 +150,23 @@ function report(data) {
|
|
|
146
150
|
...comData,
|
|
147
151
|
dataAbstract: MD5(JSON.stringify(comData)),
|
|
148
152
|
};
|
|
149
|
-
uni.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
},
|
|
163
|
-
});
|
|
153
|
+
uni.request({
|
|
154
|
+
url: reportUrl,
|
|
155
|
+
method: "POST",
|
|
156
|
+
header: {
|
|
157
|
+
"Content-Type": "application/json",
|
|
158
|
+
appKey: _config.token,
|
|
159
|
+
projectId: _config.token,
|
|
160
|
+
},
|
|
161
|
+
data: reportData,
|
|
162
|
+
success: function (res) {},
|
|
163
|
+
fail: function (error) {
|
|
164
|
+
console.error(error);
|
|
165
|
+
},
|
|
164
166
|
});
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
//track upload
|
|
169
|
+
//track upload-registry
|
|
168
170
|
export function onStartTrack(tData) {
|
|
169
171
|
busObj = null;
|
|
170
172
|
startTime = 0;
|
|
@@ -187,17 +189,27 @@ export function onDestroyTrack() {
|
|
|
187
189
|
|
|
188
190
|
function assemblyTrackData(type) {
|
|
189
191
|
if (busObj) {
|
|
190
|
-
let obj = getTrackObj(busObj);
|
|
192
|
+
let obj = getTrackObj(busObj, platform);
|
|
191
193
|
let trackData = null;
|
|
194
|
+
let cirtemp = -1;
|
|
192
195
|
if (type === "destroy") {
|
|
196
|
+
cirtemp = 3;
|
|
193
197
|
startTime = (Date.now() - startTimeLong) / 1000;
|
|
198
|
+
} else {
|
|
199
|
+
if (startTime === 0) {
|
|
200
|
+
startTime === 0;
|
|
201
|
+
cirtemp = 1;
|
|
202
|
+
} else {
|
|
203
|
+
startTime = 15;
|
|
204
|
+
cirtemp = 2;
|
|
205
|
+
}
|
|
194
206
|
}
|
|
195
207
|
trackData = {
|
|
196
208
|
busSegment: busObj.busSegment,
|
|
197
|
-
circulation:
|
|
209
|
+
circulation: cirtemp,
|
|
198
210
|
ctk: busObj.ctk ? busObj.ctk : "",
|
|
199
211
|
domain: obj.domain,
|
|
200
|
-
duration: startTime
|
|
212
|
+
duration: startTime,
|
|
201
213
|
module: busObj.module,
|
|
202
214
|
path: obj.path,
|
|
203
215
|
properties: busObj.extend_param
|
|
@@ -244,24 +256,11 @@ function reportTrack(data) {
|
|
|
244
256
|
});
|
|
245
257
|
}
|
|
246
258
|
|
|
247
|
-
function getCurPath() {
|
|
248
|
-
if (platform) {
|
|
249
|
-
if (platform == "wx") {
|
|
250
|
-
let gcp = getCurrentPages();
|
|
251
|
-
return gcp ? gcp[gcp.length - 1].route : "/";
|
|
252
|
-
} else if (platform == "web") {
|
|
253
|
-
return window.location.hostname;
|
|
254
|
-
} else if (platform == "android" || platform === "ios") {
|
|
255
|
-
return "";
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
259
|
function commonData(allData) {
|
|
261
260
|
return {
|
|
262
261
|
app: appData,
|
|
263
262
|
data: allData,
|
|
264
|
-
|
|
263
|
+
device: deviceData,
|
|
265
264
|
lsi: localLsi,
|
|
266
265
|
projectId: _config.token,
|
|
267
266
|
userAgent: uAgent ? uAgent : "",
|
|
@@ -290,7 +289,7 @@ function getBaseicInfo() {
|
|
|
290
289
|
platform = "wx";
|
|
291
290
|
appData = wxInfo();
|
|
292
291
|
}
|
|
293
|
-
deviceData = getDeviceInfo(res);
|
|
292
|
+
deviceData = getDeviceInfo(res, platform);
|
|
294
293
|
},
|
|
295
294
|
fail: function (error) {
|
|
296
295
|
deviceData = getDeviceInfoError();
|
|
@@ -298,10 +297,7 @@ function getBaseicInfo() {
|
|
|
298
297
|
complete: function () {
|
|
299
298
|
uni.getNetworkType({
|
|
300
299
|
success(res) {
|
|
301
|
-
deviceData =
|
|
302
|
-
...deviceData,
|
|
303
|
-
network: res.networkType,
|
|
304
|
-
};
|
|
300
|
+
deviceData.network = res.networkType;
|
|
305
301
|
},
|
|
306
302
|
});
|
|
307
303
|
},
|
package/lsi-md5.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
// 此js在npm build,根据name + version + md5后会自动修改package.json中的lsi
|
|
2
2
|
// 注:发给后端,作为标识依据和上报字段lsi值
|
|
3
|
-
import fs from
|
|
4
|
-
import MD5 from
|
|
5
|
-
const packageJson = JSON.parse(fs.readFileSync(
|
|
6
|
-
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import MD5 from "md5";
|
|
5
|
+
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
|
|
7
6
|
|
|
8
7
|
const { name, version } = packageJson;
|
|
9
8
|
// MD5
|
|
10
9
|
const combinedString = name + "-" + version;
|
|
11
10
|
const md5Str = MD5(combinedString);
|
|
12
|
-
packageJson.lsi = md5Str;
|
|
11
|
+
packageJson.lsi = md5Str + "#" + version;
|
|
13
12
|
//base64
|
|
14
13
|
// const combinedString = name.substring(0, 16) + "v" + version;
|
|
15
14
|
// const base64Str = btoa(combinedString);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "visual-buried-point-platform-uni",
|
|
3
|
-
"version": "1.0.0-alpha",
|
|
4
|
-
"lsi": "
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
4
|
+
"lsi": "2fd45101ac37118f6d823ce6589d52fb#1.0.0-alpha.09",
|
|
5
5
|
"description": "To make it easy for you to get started with GitLab, here's a list of recommended next steps.",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
package/tools.js
CHANGED
|
@@ -64,11 +64,14 @@ export function webH5Info(result) {
|
|
|
64
64
|
|
|
65
65
|
//微信的appInfo
|
|
66
66
|
export function wxInfo() {
|
|
67
|
-
|
|
67
|
+
const accInfo = uni.getAccountInfoSync();
|
|
68
|
+
const bInfo = uni.getAppBaseInfo();
|
|
68
69
|
return {
|
|
69
|
-
name: "",
|
|
70
|
-
packageName: accInfo ? accInfo.appId : "",
|
|
71
|
-
version: accInfo
|
|
70
|
+
name: bInfo.appName ? bInfo.appName : "",
|
|
71
|
+
packageName: accInfo ? accInfo.miniProgram.appId : "",
|
|
72
|
+
version: accInfo
|
|
73
|
+
? accInfo.miniProgram.envVersion + accInfo.miniProgram.version
|
|
74
|
+
: "",
|
|
72
75
|
carrier: "mini",
|
|
73
76
|
ecology: "wechat",
|
|
74
77
|
};
|
|
@@ -81,6 +84,8 @@ export function getAppInfo(result) {
|
|
|
81
84
|
name: result.appName,
|
|
82
85
|
version: version ? version : "",
|
|
83
86
|
carrier: "app",
|
|
87
|
+
packageName: "",
|
|
88
|
+
ecology: "",
|
|
84
89
|
};
|
|
85
90
|
if (result.platform === "android") {
|
|
86
91
|
let osName = "android";
|
|
@@ -88,47 +93,44 @@ export function getAppInfo(result) {
|
|
|
88
93
|
if (result.romName.includes("HarmonyOS")) {
|
|
89
94
|
osName = "harmonyOS";
|
|
90
95
|
}
|
|
91
|
-
app =
|
|
92
|
-
|
|
93
|
-
packageName: pkName ? pkName : "",
|
|
94
|
-
ecology: osName,
|
|
95
|
-
};
|
|
96
|
+
app.packageName = pkName ? pkName : "";
|
|
97
|
+
app.ecology = osName;
|
|
96
98
|
} else if (result.platform === "ios") {
|
|
97
99
|
let pkName = plus.ios
|
|
98
100
|
.importClass("NSBundle")
|
|
99
101
|
.mainBundle()
|
|
100
102
|
.bundleIdentifier();
|
|
101
|
-
app =
|
|
102
|
-
|
|
103
|
-
packageName: pkName ? pkName : "",
|
|
104
|
-
ecology: "ios",
|
|
105
|
-
};
|
|
103
|
+
app.packageName = pkName ? pkName : "";
|
|
104
|
+
app.ecology = "ios";
|
|
106
105
|
} else {
|
|
107
|
-
app =
|
|
108
|
-
...app,
|
|
109
|
-
packageName: "",
|
|
110
|
-
version: "",
|
|
111
|
-
ecology: "unknown",
|
|
112
|
-
};
|
|
106
|
+
app.ecology = "unknown";
|
|
113
107
|
}
|
|
114
108
|
return app;
|
|
115
109
|
}
|
|
116
110
|
|
|
117
|
-
function getCurDeviceType(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
function getCurDeviceType(res, platform) {
|
|
112
|
+
if (platform !== "wx") {
|
|
113
|
+
const userAgent = res.ua.toLowerCase();
|
|
114
|
+
if (/(windows|win32|win64|wow64)/.test(userAgent)) {
|
|
115
|
+
return 1;
|
|
116
|
+
} else if (/(linux|android)/.test(userAgent)) {
|
|
117
|
+
return 2;
|
|
118
|
+
} else if (/(macintosh|mac os x|iphone|ipad|ipod)/.test(userAgent)) {
|
|
119
|
+
return 2;
|
|
120
|
+
} else {
|
|
121
|
+
return 2;
|
|
122
|
+
}
|
|
125
123
|
} else {
|
|
126
|
-
|
|
124
|
+
if (res.deviceType === "pc") {
|
|
125
|
+
return 1;
|
|
126
|
+
} else {
|
|
127
|
+
return 2;
|
|
128
|
+
}
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
//获取设备信息
|
|
131
|
-
export function getDeviceInfo(res) {
|
|
133
|
+
export function getDeviceInfo(res, platform) {
|
|
132
134
|
let device = {
|
|
133
135
|
lang: res.osLanguage ? res.osLanguage : res.hostLanguage,
|
|
134
136
|
brand: res.deviceBrand + " " + res.deviceModel,
|
|
@@ -139,7 +141,7 @@ export function getDeviceInfo(res) {
|
|
|
139
141
|
browserVersion: res.browserVersion,
|
|
140
142
|
color: "",
|
|
141
143
|
deviceId: res.deviceId,
|
|
142
|
-
deviceType: getCurDeviceType(res
|
|
144
|
+
deviceType: getCurDeviceType(res, platform),
|
|
143
145
|
network: "",
|
|
144
146
|
};
|
|
145
147
|
return device;
|
|
@@ -162,48 +164,35 @@ export function getDeviceInfoError() {
|
|
|
162
164
|
};
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
|
|
166
|
-
export function getTrackObj(busObj) {
|
|
167
|
-
//uni 通用h5、app、wx拿到当前路由栈
|
|
167
|
+
//uni 通用h5、app、wx拿到当前路由栈
|
|
168
|
+
export function getTrackObj(busObj, platform) {
|
|
168
169
|
const pages = getCurrentPages();
|
|
169
170
|
const gcp = pages[pages.length - 1];
|
|
170
|
-
//h5
|
|
171
|
-
let wl = window.location;
|
|
172
|
-
let docTitle = document.title;
|
|
173
|
-
let refurl = document.referrer;
|
|
174
|
-
let parsedUrl;
|
|
175
|
-
if (refurl) {
|
|
176
|
-
parsedUrl = new URL(refurl);
|
|
177
|
-
} else {
|
|
178
|
-
let busRefUrl = busObj.sourceUrl;
|
|
179
|
-
if (busRefUrl) {
|
|
180
|
-
parsedUrl = new URL(busRefUrl);
|
|
181
|
-
} else {
|
|
182
|
-
parsedUrl = "";
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
171
|
if (gcp) {
|
|
186
|
-
let domain = "";
|
|
187
|
-
let url = "";
|
|
188
|
-
if (busObj.domain) {
|
|
189
|
-
domain = busObj.domain;
|
|
190
|
-
} else {
|
|
191
|
-
domain = wl.hostname ? wl.hostname : "";
|
|
192
|
-
}
|
|
193
|
-
if (busObj.url) {
|
|
194
|
-
url = busObj.url;
|
|
195
|
-
} else {
|
|
196
|
-
url = wl.href ? wl.href : "";
|
|
197
|
-
}
|
|
198
172
|
return {
|
|
199
173
|
path: gcp.route,
|
|
200
|
-
domain: domain,
|
|
201
|
-
url: url,
|
|
202
|
-
circulation:
|
|
203
|
-
visitPage:
|
|
204
|
-
sourceDomain:
|
|
205
|
-
sourceUrl:
|
|
206
|
-
title:
|
|
174
|
+
domain: busObj.domain ? busObj.domain : "",
|
|
175
|
+
url: busObj.url ? busObj.url : getUrl(platform),
|
|
176
|
+
circulation: pages.length > 1 ? 2 : 1,
|
|
177
|
+
visitPage: pages.length,
|
|
178
|
+
sourceDomain: busObj.sourceDomain ? busObj.sourceDomain : "",
|
|
179
|
+
sourceUrl: busObj.sourceUrl ? busObj.sourceUrl : "",
|
|
180
|
+
title: busObj.title ? busObj.title : "",
|
|
207
181
|
};
|
|
208
182
|
}
|
|
209
183
|
}
|
|
184
|
+
|
|
185
|
+
export function getCurPath() {
|
|
186
|
+
const pages = getCurrentPages();
|
|
187
|
+
const gcp = pages[pages.length - 1];
|
|
188
|
+
return gcp ? gcp.route : "/";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function getUrl(platform) {
|
|
192
|
+
if (!platform) return "";
|
|
193
|
+
if (platform === "web" || platform === "h5") {
|
|
194
|
+
return window.location.href;
|
|
195
|
+
} else {
|
|
196
|
+
return "";
|
|
197
|
+
}
|
|
198
|
+
}
|