visual-buried-point-platform-uni 1.0.0-alpha.6 → 1.0.0-alpha.8
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 +5 -7
- package/index.js +6 -19
- package/package.json +2 -2
- package/tools.js +20 -6
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
## Uni版自定义埋点SDK集成文档
|
|
2
2
|
|
|
3
|
+
### SDK更新日志
|
|
4
|
+
- 1.0.0-alpha.07 最新uni、终端通用埋点sdk;
|
|
5
|
+
|
|
3
6
|
### 1、引入方式
|
|
4
7
|
|
|
5
8
|
```js
|
|
6
|
-
npm
|
|
7
|
-
|
|
9
|
+
//内网npm链接:http://verdaccio.gogdev.cn/
|
|
10
|
+
npm install visual-buried-point-platform-uni
|
|
8
11
|
```
|
|
9
12
|
|
|
10
13
|
### 2、初始化方式
|
|
11
14
|
|
|
12
|
-
**app.js**
|
|
13
|
-
|
|
14
15
|
```js
|
|
15
|
-
//require引入
|
|
16
16
|
import { init } from 'visual-buried-point-platform-uni'
|
|
17
17
|
onLaunch: function() {
|
|
18
18
|
//初始化sdk
|
|
@@ -47,8 +47,6 @@ setUserId(123456);
|
|
|
47
47
|
setUserId("");
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
50
|
### 4、自定义事件上报
|
|
53
51
|
|
|
54
52
|
- sdk初始化后,可通过 ***setCustomEvent()*** 方法上报自定义埋点事件,并为事件添加属性值:
|
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
|
|
|
@@ -81,7 +83,6 @@ function startGlobalTime() {
|
|
|
81
83
|
clearInterval(cInterval);
|
|
82
84
|
cInterval = setInterval(() => {
|
|
83
85
|
let cData = getSData();
|
|
84
|
-
// console.log("storage data " + JSON.stringify(cData));
|
|
85
86
|
if (cData) {
|
|
86
87
|
reportCustom(cData);
|
|
87
88
|
delSData();
|
|
@@ -108,7 +109,7 @@ export function setCustomEvent(data) {
|
|
|
108
109
|
reportData = {
|
|
109
110
|
ctk: data.$ctk ? data.$ctk : "",
|
|
110
111
|
duration: "",
|
|
111
|
-
element: null,
|
|
112
|
+
element: data.$element ? data.$element : null,
|
|
112
113
|
eventId: data.$event_id ? data.$event_id : "",
|
|
113
114
|
event: data.$event_code ? data.$event_code : "",
|
|
114
115
|
groupId: "",
|
|
@@ -119,13 +120,12 @@ export function setCustomEvent(data) {
|
|
|
119
120
|
pageId: MD5(_path),
|
|
120
121
|
path: _path,
|
|
121
122
|
title: _page.title ? _page.title : "",
|
|
123
|
+
url: _path ? _path : getUrl(platform),
|
|
122
124
|
},
|
|
123
|
-
path: data.$path ? data.$path : "",
|
|
124
125
|
properties: data.$extend_param ? JSON.stringify(data.$extend_param) : "",
|
|
125
126
|
traceId: "",
|
|
126
127
|
trackId: trackId,
|
|
127
128
|
triggerTime: timeToStr(Date.now()),
|
|
128
|
-
url: url,
|
|
129
129
|
};
|
|
130
130
|
if (reportData) {
|
|
131
131
|
addCache(reportData);
|
|
@@ -166,7 +166,7 @@ function reportCustom(data) {
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
//track upload
|
|
169
|
+
//track upload-registry
|
|
170
170
|
export function onStartTrack(tData) {
|
|
171
171
|
busObj = null;
|
|
172
172
|
startTime = 0;
|
|
@@ -189,7 +189,7 @@ export function onDestroyTrack() {
|
|
|
189
189
|
|
|
190
190
|
function assemblyTrackData(type) {
|
|
191
191
|
if (busObj) {
|
|
192
|
-
let obj = getTrackObj(busObj);
|
|
192
|
+
let obj = getTrackObj(busObj, platform);
|
|
193
193
|
let trackData = null;
|
|
194
194
|
if (type === "destroy") {
|
|
195
195
|
startTime = (Date.now() - startTimeLong) / 1000;
|
|
@@ -246,19 +246,6 @@ function reportTrack(data) {
|
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
function getCurPath() {
|
|
250
|
-
// if (platform === "android" || platform === "ios") {
|
|
251
|
-
// return "";
|
|
252
|
-
// } else {
|
|
253
|
-
// const pages = getCurrentPages();
|
|
254
|
-
// const gcp = pages[pages.length - 1];
|
|
255
|
-
// return gcp ? gcp.route : "/";
|
|
256
|
-
// }
|
|
257
|
-
const pages = getCurrentPages();
|
|
258
|
-
const gcp = pages[pages.length - 1];
|
|
259
|
-
return gcp ? gcp.route : "/";
|
|
260
|
-
}
|
|
261
|
-
|
|
262
249
|
function commonData(allData) {
|
|
263
250
|
return {
|
|
264
251
|
app: appData,
|
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.08",
|
|
4
|
+
"lsi": "ecd31a049b2d07f61d9d425b009cd74a",
|
|
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
|
@@ -164,21 +164,35 @@ export function getDeviceInfoError() {
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
export function getTrackObj(busObj) {
|
|
169
|
-
//uni 通用h5、app、wx拿到当前路由栈
|
|
167
|
+
//uni 通用h5、app、wx拿到当前路由栈
|
|
168
|
+
export function getTrackObj(busObj, platform) {
|
|
170
169
|
const pages = getCurrentPages();
|
|
171
170
|
const gcp = pages[pages.length - 1];
|
|
172
171
|
if (gcp) {
|
|
173
172
|
return {
|
|
174
173
|
path: gcp.route,
|
|
175
174
|
domain: busObj.domain ? busObj.domain : "",
|
|
176
|
-
url: busObj.url ? busObj.url :
|
|
177
|
-
circulation:
|
|
178
|
-
visitPage:
|
|
175
|
+
url: busObj.url ? busObj.url : getUrl(platform),
|
|
176
|
+
circulation: pages.length > 1 ? 2 : 1,
|
|
177
|
+
visitPage: pages.length,
|
|
179
178
|
sourceDomain: busObj.sourceDomain ? busObj.sourceDomain : "",
|
|
180
179
|
sourceUrl: busObj.sourceUrl ? busObj.sourceUrl : "",
|
|
181
180
|
title: busObj.title ? busObj.title : "",
|
|
182
181
|
};
|
|
183
182
|
}
|
|
184
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
|
+
}
|