visual-buried-point-platform-uni 1.0.0-alpha.11 → 1.0.0-alpha.12

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/autoutils.js ADDED
@@ -0,0 +1,167 @@
1
+ import { reportTrackEventServer, _config } from "./index.js";
2
+ import { sdkTrackIdVal, Global, pagesArray, timeToStr } from "./tools.js";
3
+
4
+ export const AUTOTRACKTYPE = {
5
+ ENTER: "enter",
6
+ LOOP: "loop",
7
+ LEAVE: "leave",
8
+ };
9
+ // PVUV存储的key值
10
+ const BPNPVUV = "UNIBPNPVUVSrcData";
11
+ const BPNPVUVFail = "UNIBPNPVUVFailData";
12
+ // 采集数据
13
+ let atDuration;
14
+ let atEnterTimeLong;
15
+ let atLoopTimeLong;
16
+ let cirtemp;
17
+ let _pageObj;
18
+ let atInterval = null;
19
+
20
+ export const autoStartTrackPVUV = (objParams) => {
21
+ clearInterval(atInterval);
22
+ _pageObj = null;
23
+ _pageObj = objParams;
24
+ autoTrackData(AUTOTRACKTYPE.ENTER);
25
+ atInterval = setInterval(() => {
26
+ autoTrackData(AUTOTRACKTYPE.LOOP);
27
+ }, 15000);
28
+ };
29
+
30
+ export const autoStopTrackPVUV = () => {
31
+ autoTrackData(AUTOTRACKTYPE.LEAVE);
32
+ clearInterval(atInterval);
33
+ };
34
+
35
+ function autoTrackData(type) {
36
+ if (type === AUTOTRACKTYPE.ENTER) {
37
+ cirtemp = 1;
38
+ atDuration = 0;
39
+ atEnterTimeLong = Date.now();
40
+ atLoopTimeLong = Date.now();
41
+ } else if (type === AUTOTRACKTYPE.LOOP) {
42
+ cirtemp = 2;
43
+ atDuration = 15;
44
+ atLoopTimeLong = Date.now();
45
+ } else if (type === AUTOTRACKTYPE.LEAVE) {
46
+ cirtemp = 3;
47
+ atDuration = Math.ceil((Date.now() - atLoopTimeLong) / 1000);
48
+ }
49
+ if (_pageObj) {
50
+ const puvData = {
51
+ busSegment: _pageObj.busSegment || "",
52
+ circulation: cirtemp,
53
+ ctk: "",
54
+ domain: _pageObj.domain,
55
+ duration: atDuration,
56
+ module: _pageObj.module || "",
57
+ path: _pageObj.path,
58
+ url: _pageObj.url,
59
+ sourceDomain: _pageObj.sourceDomain,
60
+ sourceUrl: _pageObj.sourceUrl,
61
+ properties: _pageObj.properties,
62
+ title: _pageObj.title,
63
+ traceId: "",
64
+ trackId: sdkTrackIdVal(),
65
+ visitPage: _pageObj.visitPage,
66
+ visitTime: timeToStr(atEnterTimeLong),
67
+ };
68
+ if (puvData) {
69
+ insertPVUVData(puvData);
70
+ }
71
+ }
72
+ }
73
+
74
+ // 插入数据
75
+ export function insertPVUVData(pData) {
76
+ let td = uni.getStorageSync(BPNPVUV);
77
+ let allPvuvData = td ? JSON.parse(td) : [];
78
+ if (pData) {
79
+ allPvuvData.push({ ...pData, status: 0 });
80
+ uni.setStorageSync(BPNPVUV, JSON.stringify(allPvuvData));
81
+ }
82
+ }
83
+
84
+ // 自动采集对象
85
+ export function autoPageObj(cpath, clength, cpages) {
86
+ let _pObj = pagesArray.find((obj) => obj.path === cpath);
87
+ let pf = Global.platform;
88
+ let url = "";
89
+ let domain = "";
90
+ let srcUrl = "";
91
+ let srcDomain = "";
92
+ if (pf) {
93
+ if (pf === "web" || pf === "h5") {
94
+ url = window.location.href;
95
+ domain = window.location.hostname;
96
+ if (document.referrer) {
97
+ let parsedUrl = new URL(document.referrer);
98
+ srcUrl = parsedUrl || "";
99
+ srcDomain = parsedUrl.hostname || "";
100
+ }
101
+ } else {
102
+ url = cpath;
103
+ if (clength > 1) {
104
+ let beforePage = cpages[clength - 2];
105
+ srcUrl = beforePage.route;
106
+ }
107
+ domain = _config.domain ? _config.domain : cpath;
108
+ }
109
+ }
110
+ return {
111
+ path: _pObj && _pObj.path ? _pObj.path : cpath,
112
+ busSegment:
113
+ _pObj && _pObj.busSegment ? _pObj.busSegment : _config.busSegment || "",
114
+ module: _pObj && _pObj.module ? _pObj.module : _config.module || "",
115
+ properties: _pObj && _pObj.properties ? _pObj.properties : "",
116
+ domain: domain,
117
+ url: url,
118
+ visitPage: clength,
119
+ sourceDomain: srcDomain,
120
+ sourceUrl: srcUrl,
121
+ title: _pObj && _pObj.title ? _pObj.title : "",
122
+ };
123
+ }
124
+
125
+ /**
126
+ * 查询数据
127
+ * 0 未上报 2上报失败
128
+ */
129
+ export function queryTrackDataUpload() {
130
+ let td = uni.getStorageSync(BPNPVUV);
131
+ uni.setStorageSync(BPNPVUV, "");
132
+ const arr = td ? JSON.parse(td) : [];
133
+ let uploadArray = [];
134
+ let ftd = uni.getStorageSync(BPNPVUVFail);
135
+ const failArr = ftd ? JSON.parse(ftd) : [];
136
+ if (arr.length) {
137
+ uploadArray.push(...arr);
138
+ }
139
+ if (failArr.length) {
140
+ uploadArray.push(...failArr);
141
+ }
142
+ if (uploadArray && uploadArray.length) {
143
+ uploadArray.forEach((item) => {
144
+ delete item.status;
145
+ });
146
+ reportTrackEventServer("track", uploadArray, BPNPVUVFail);
147
+ }
148
+ }
149
+
150
+ // 更新当前页的业务方设置的对象
151
+ export function uUpdatePageExtraArray(d) {
152
+ const pages = getCurrentPages();
153
+ let page = pages[pages.length - 1];
154
+ const index = pagesArray.findIndex((item) => item.path === page.route);
155
+ let temp = {
156
+ path: page.route,
157
+ properties: d.properties ? JSON.stringify(d.properties) : "",
158
+ busSegment: d.busSegment ? d.busSegment : "",
159
+ module: d.module ? d.module : "",
160
+ title: d.title ? d.title : "",
161
+ };
162
+ if (index !== -1) {
163
+ pagesArray[index] = temp;
164
+ } else {
165
+ pagesArray.push(temp);
166
+ }
167
+ }
package/eventutils.js ADDED
@@ -0,0 +1,95 @@
1
+ import MD5 from "md5";
2
+ import { addCache, clearCache, getCache } from "./cache.js";
3
+ import { reportTrackEventServer } from "./index.js";
4
+ import { sdkTrackIdVal, timeToStr } from "./tools.js";
5
+
6
+ //Event存储的key值
7
+ const BPNEvent = "UNIBPNEventSrcData";
8
+ const BPNEventFail = "UNIBPNEventFailData";
9
+ let timerCustom;
10
+
11
+ function getCurPath() {
12
+ const pages = getCurrentPages();
13
+ const gcp = pages[pages.length - 1];
14
+ return gcp ? gcp.route : "/";
15
+ }
16
+
17
+ // 自定义部分 type=>custom event=>到四种具体事件类型 extend_param 扩展字段
18
+ export function eventCommonStore(data) {
19
+ const _page = data.$page ? data.$page : "";
20
+ const _path = _page.path ? _page.path : getCurPath();
21
+ const reportEventData = {
22
+ ctk: data.$ctk ? data.$ctk : "",
23
+ duration: "",
24
+ element: data.$element ? data.$element : null,
25
+ eventId: data.$event_id ? data.$event_id : "",
26
+ event: data.$event_code ? data.$event_code : "",
27
+ groupId: "",
28
+ busSegment: data.$busSegment,
29
+ module: data.$module,
30
+ page: {
31
+ domain: _page.domain ? _page.domain : "",
32
+ pageId: MD5(_path),
33
+ path: _path || "",
34
+ title: _page.title || "",
35
+ url: _path || "",
36
+ },
37
+ properties: data.$extend_param ? JSON.stringify(data.$extend_param) : "",
38
+ traceId: "",
39
+ trackId: sdkTrackIdVal(),
40
+ triggerTime: timeToStr(Date.now()),
41
+ };
42
+
43
+ if (reportEventData) {
44
+ addCache(reportEventData);
45
+ clearTimeout(timerCustom);
46
+ timerCustom = setTimeout(() => {
47
+ const data = getCache();
48
+ if (data.length) {
49
+ insertEventData(data);
50
+ clearCache();
51
+ }
52
+ }, 2000);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * 插入可视化和Event数据合并
58
+ */
59
+ export function insertEventData(cData) {
60
+ console.log("写入Event数据 ", cData);
61
+ let cd = uni.getStorageSync(BPNEvent);
62
+ let allEventData = cd ? JSON.parse(cd) : [];
63
+ if (cData && cData.length) {
64
+ cData.forEach((item) => {
65
+ item.status = 0;
66
+ allEventData.push(item);
67
+ });
68
+ uni.setStorageSync(BPNEvent, JSON.stringify(allEventData));
69
+ }
70
+ }
71
+
72
+ /**
73
+ * 查询自定义数据
74
+ * 0 未上报/上报失败
75
+ */
76
+ export function queryEventDataUpload() {
77
+ let cd = uni.getStorageSync(BPNEvent);
78
+ uni.setStorageSync(BPNEvent, "");
79
+ const arr = cd ? JSON.parse(cd) : [];
80
+ let uploadArray = [];
81
+ let fcd = uni.getStorageSync(BPNEventFail);
82
+ const failArr = fcd ? JSON.parse(fcd) : [];
83
+ if (arr.length) {
84
+ uploadArray.push(...arr);
85
+ }
86
+ if (failArr.length) {
87
+ uploadArray.push(...failArr);
88
+ }
89
+ if (uploadArray && uploadArray.length) {
90
+ uploadArray.forEach((item) => {
91
+ delete item.status;
92
+ });
93
+ reportTrackEventServer("event", uploadArray, BPNEventFail);
94
+ }
95
+ }
package/index.js CHANGED
@@ -1,52 +1,41 @@
1
1
  import MD5 from "md5";
2
+ import { queryTrackDataUpload, uUpdatePageExtraArray } from "./autoutils.js";
3
+ import { setReportUrl } from "./config.js";
4
+ import { eventCommonStore, queryEventDataUpload } from "./eventutils.js";
5
+ import { destroyTrackReport, startTrackReport } from "./manualutils.js";
2
6
  import pk from "./package.json";
3
- import { addCache, getCache, clearCache } from "./cache.js";
4
- import { addSData, getSData, delSData } from "./bpstorage.js";
7
+ import { uniInterceptorListener } from "./pageListener.js";
5
8
  import {
6
- randomUUID,
7
- webH5Info,
8
- wxInfo,
9
9
  getAppInfo,
10
10
  getDeviceInfo,
11
11
  getDeviceInfoError,
12
- timeToStr,
13
- getTrackObj,
14
- getCurPath,
15
- getUrl,
12
+ getWebH5Info,
13
+ randomUUID,
14
+ getWXInfo,
15
+ Global,
16
+ sdkTrackIdVal,
16
17
  } from "./tools.js";
17
- import { setReportUrl } from "./config.js";
18
18
 
19
19
  const localLsi = pk.lsi;
20
- let platform = "";
21
- let uAgent = "";
22
- let reportUrl = "";
23
- let reportTrackUrl = "";
24
- let trackId = "";
25
20
  let _comInfo = { distinctId: "", anonymousId: "" };
26
21
  let appData = {};
27
22
  let deviceData = {};
28
- let _config = {
23
+ export let _config = {
29
24
  env: "production",
30
25
  token: "",
31
26
  srcDomain: "",
32
27
  flushInterval: 15,
28
+ isCompatible: "",
29
+ signTrackArray: [],
33
30
  };
34
- //custom
35
- let timer = null;
36
- //track upload interval
37
- let tInterval = null;
38
- let busObj = null;
39
- let startTime = 0;
40
- let startTimeLong = 0;
41
31
 
42
32
  //common global upload interval
43
- let cInterval = null;
44
-
33
+ let uglInterval = null;
45
34
  export function init(config) {
46
35
  if (config) {
47
36
  let _cf = setReportUrl(config.env ? config.env : "");
48
- reportUrl = _cf.reportUrl;
49
- reportTrackUrl = _cf.reportTrackUrl;
37
+ Global.upEventUrl = _cf.reportUrl;
38
+ Global.upTrackUrl = _cf.reportTrackUrl;
50
39
  if (config.flushInterval) {
51
40
  if (config.flushInterval < 5) {
52
41
  config.flushInterval = 15;
@@ -57,8 +46,11 @@ export function init(config) {
57
46
  _config = {
58
47
  env: config.env,
59
48
  token: config.token ? config.token : "",
60
- srcDomain: config.sourceDomain ? config.sourceDomain : "",
49
+ domain: config.domain ? config.domain : "",
61
50
  flushInterval: config.flushInterval,
51
+ isCompatible:
52
+ config.isCompatible != undefined ? config.isCompatible : true,
53
+ signTrackArray: config.signTrackArray || [],
62
54
  };
63
55
  getBaseicInfo();
64
56
  _comInfo.distinctId = uni.getStorageSync("v_userId")
@@ -69,25 +61,23 @@ export function init(config) {
69
61
  _comInfo.anonymousId = randomUUID();
70
62
  uni.setStorageSync("v_anonId", _comInfo.anonymousId);
71
63
  }
72
- if (!trackId) {
73
- trackId = Date.now().toString();
74
- }
64
+ sdkTrackIdVal();
75
65
  } else {
76
66
  console.log("init config error, please check config!");
77
67
  }
68
+ // 开启全局定时器
78
69
  startGlobalTime();
70
+ // 监听页面的加载、卸载
71
+ uniInterceptorListener();
79
72
  }
80
73
 
81
74
  //the general custom reportCustom interval is enabled
82
75
  function startGlobalTime() {
83
- clearInterval(cInterval);
84
- cInterval = setInterval(() => {
85
- let cData = getSData();
86
- if (cData) {
87
- reportCustom(cData);
88
- delSData();
89
- }
90
- }, _config.flushInterval * 1000);
76
+ clearInterval(uglInterval);
77
+ uglInterval = setInterval(() => {
78
+ queryEventDataUpload();
79
+ queryTrackDataUpload();
80
+ }, 15000);
91
81
  }
92
82
 
93
83
  //bind userID
@@ -101,157 +91,62 @@ export function setUserId(userId) {
101
91
  }
102
92
  }
103
93
 
104
- //set custom event
105
- export function setCustomEvent(data) {
106
- let reportData = null;
107
- const _page = data.$page ? data.$page : "";
108
- const _path = _page.path ? _page.path : getCurPath();
109
- reportData = {
110
- ctk: data.$ctk ? data.$ctk : "",
111
- duration: "",
112
- element: data.$element ? data.$element : null,
113
- eventId: data.$event_id ? data.$event_id : "",
114
- event: data.$event_code ? data.$event_code : "",
115
- groupId: "",
116
- busSegment: data.$busSegment,
117
- module: data.$module,
118
- page: {
119
- domain: _page.domain ? _page.domain : "",
120
- pageId: MD5(_path),
121
- path: _path,
122
- title: _page.title ? _page.title : "",
123
- url: _path ? _path : getUrl(platform),
124
- },
125
- properties: data.$extend_param ? JSON.stringify(data.$extend_param) : "",
126
- traceId: "",
127
- trackId: trackId,
128
- triggerTime: timeToStr(Date.now()),
129
- };
130
- if (reportData) {
131
- addCache(reportData);
132
- clearTimeout(timer);
133
- timer = setTimeout(() => {
134
- const data = getCache();
135
- if (data.length) {
136
- addSData(data);
137
- clearCache();
138
- }
139
- }, 1000);
140
- }
94
+ //对外开放,获取跟踪Id
95
+ export function getTrackId() {
96
+ return sdkTrackIdVal();
141
97
  }
142
98
 
143
- function reportCustom(data) {
144
- if (!reportUrl) {
145
- console.error("please set upload data reportUrl");
146
- return;
147
- }
148
- const comData = commonData(data);
149
- const reportData = {
150
- ...comData,
151
- dataAbstract: MD5(JSON.stringify(comData)),
152
- };
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
- },
166
- });
99
+ // set custom event
100
+ export function setCustomEvent(data) {
101
+ eventCommonStore(data);
167
102
  }
168
103
 
169
104
  //track upload-registry
170
105
  export function onStartTrack(tData) {
171
- busObj = null;
172
- startTime = 0;
173
- startTimeLong = Date.now();
174
- busObj = tData;
175
- clearInterval(tInterval);
176
- assemblyTrackData("start");
177
- tInterval = setInterval(() => {
178
- startTime += 15;
179
- startTimeLong = Date.now();
180
- assemblyTrackData("start");
181
- }, 15 * 1000);
106
+ startTrackReport(tData);
182
107
  }
183
108
 
184
- //track upload-销毁
109
+ //track upload-Destroy
185
110
  export function onDestroyTrack() {
186
- assemblyTrackData("destroy");
187
- clearInterval(tInterval);
111
+ destroyTrackReport();
188
112
  }
189
113
 
190
- function assemblyTrackData(type) {
191
- if (busObj) {
192
- let obj = getTrackObj(busObj, platform);
193
- let trackData = null;
194
- let cirtemp = -1;
195
- if (type === "destroy") {
196
- cirtemp = 3;
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
- }
206
- }
207
- trackData = {
208
- busSegment: busObj.busSegment,
209
- circulation: cirtemp,
210
- ctk: busObj.ctk ? busObj.ctk : "",
211
- domain: obj.domain,
212
- duration: startTime,
213
- module: busObj.module,
214
- path: obj.path,
215
- properties: busObj.extend_param
216
- ? JSON.stringify(busObj.extend_param)
217
- : "",
218
- sourceDomain: obj.sourceDomain ? obj.sourceDomain : _config.srcDomain,
219
- sourceUrl: obj.sourceUrl,
220
- title: obj.title,
221
- traceId: busObj.traceId ? busObj.traceId : "",
222
- trackId: trackId,
223
- url: obj.url,
224
- visitPage: obj.visitPage,
225
- visitTime: busObj.visitTime ? busObj.visitTime : timeToStr(Date.now()),
226
- };
227
- if (trackData) {
228
- reportTrack([trackData]);
229
- }
230
- }
114
+ // auto track 预置的属性
115
+ export function setPageExtraObj(tData) {
116
+ uUpdatePageExtraArray(tData);
231
117
  }
232
118
 
233
- // track upload data
234
- function reportTrack(data) {
235
- if (!reportTrackUrl) {
119
+ // 数据上报
120
+ export function reportTrackEventServer(upType, data, sFailKey) {
121
+ if (!upType) {
122
+ console.error("please set upload data upType");
236
123
  return;
237
124
  }
238
125
  const comData = commonData(data);
239
- const reportTrackData = {
126
+ const reportData = {
240
127
  ...comData,
241
128
  dataAbstract: MD5(JSON.stringify(comData)),
242
129
  };
243
130
  uni.request({
244
- url: reportTrackUrl,
131
+ url: upType === "event" ? Global.upEventUrl : Global.upTrackUrl,
245
132
  method: "POST",
246
133
  header: {
247
134
  "Content-Type": "application/json",
248
135
  appKey: _config.token,
249
136
  projectId: _config.token,
250
137
  },
251
- data: reportTrackData,
252
- success: function (res) {},
138
+ data: reportData,
139
+ success: function (res) {
140
+ console.log("res: ", JSON.stringify(res));
141
+ if (res && res.data) {
142
+ uni.setStorageSync(sFailKey, JSON.stringify(data));
143
+ } else {
144
+ uni.setStorageSync(sFailKey, "");
145
+ }
146
+ },
253
147
  fail: function (error) {
254
- console.error(error);
148
+ console.log("error: ", error);
149
+ uni.setStorageSync(sFailKey, JSON.stringify(data));
255
150
  },
256
151
  });
257
152
  }
@@ -263,7 +158,7 @@ function commonData(allData) {
263
158
  device: deviceData,
264
159
  lsi: localLsi,
265
160
  projectId: _config.token,
266
- userAgent: uAgent ? uAgent : "",
161
+ userAgent: Global.uAgent || "",
267
162
  anonymousId: _comInfo.anonymousId,
268
163
  userId: _comInfo.distinctId,
269
164
  };
@@ -273,23 +168,23 @@ function commonData(allData) {
273
168
  function getBaseicInfo() {
274
169
  uni.getSystemInfo({
275
170
  success: function (res) {
276
- uAgent = res.ua;
171
+ Global.uAgent = res.ua;
277
172
  let uniPlatform = res.uniPlatform;
278
173
  if (uniPlatform.includes("app")) {
279
- platform = res.osName;
174
+ Global.platform = res.osName;
280
175
  appData = getAppInfo(res);
281
176
  } else if (uniPlatform.includes("web") || uniPlatform.includes("h5")) {
282
- platform = uniPlatform;
283
- let wh5Info = webH5Info(res);
177
+ Global.platform = uniPlatform;
178
+ let wh5Info = getWebH5Info(res);
284
179
  appData = {
285
180
  ...wh5Info,
286
181
  version: _config.version ? _config.version : "unknown",
287
182
  };
288
183
  } else if (uniPlatform.includes("weixin")) {
289
- platform = "wx";
290
- appData = wxInfo();
184
+ Global.platform = "weixin";
185
+ appData = getWXInfo();
291
186
  }
292
- deviceData = getDeviceInfo(res, platform);
187
+ deviceData = getDeviceInfo(res, Global.platform);
293
188
  },
294
189
  fail: function (error) {
295
190
  deviceData = getDeviceInfoError();
package/manualutils.js ADDED
@@ -0,0 +1,68 @@
1
+ import { AUTOTRACKTYPE, insertPVUVData } from "./autoutils.js";
2
+ import { sdkTrackIdVal, getTrackObj, timeToStr } from "./tools.js";
3
+
4
+ // 流量上报采集
5
+ let startTime = 0;
6
+ let enterTimeLong = 0;
7
+ let loopTimeLong = 0;
8
+ let obj = null;
9
+ let cirtemp = -1;
10
+ let umanInterval = null;
11
+ /**
12
+ * 注册
13
+ */
14
+ export const startTrackReport = (tData) => {
15
+ clearInterval(umanInterval);
16
+ if (tData) {
17
+ assemblyTrackData(AUTOTRACKTYPE.ENTER, tData);
18
+ umanInterval = setInterval(() => {
19
+ assemblyTrackData(AUTOTRACKTYPE.LOOP, null);
20
+ }, 15000);
21
+ }
22
+ };
23
+
24
+ /**
25
+ * 销毁
26
+ */
27
+ export const destroyTrackReport = () => {
28
+ onTrackReport(AUTOTRACKTYPE.LEAVE);
29
+ clearInterval(umanInterval);
30
+ };
31
+
32
+ function assemblyTrackData(type, tData) {
33
+ if (type === AUTOTRACKTYPE.ENTER) {
34
+ cirtemp = 1;
35
+ startTime = 0;
36
+ enterTimeLong = Date.now();
37
+ loopTimeLong = Date.now();
38
+ obj = getTrackObj(tData);
39
+ } else if (type === AUTOTRACKTYPE.LOOP) {
40
+ cirtemp = 2;
41
+ startTime = 15;
42
+ loopTimeLong = Date.now();
43
+ } else if (type === AUTOTRACKTYPE.LEAVE) {
44
+ cirtemp = 3;
45
+ startTime = Math.ceil((Date.now() - loopTimeLong) / 1000);
46
+ }
47
+ const puvData = {
48
+ busSegment: obj.busSegment,
49
+ circulation: cirtemp,
50
+ ctk: "",
51
+ domain: obj.domain,
52
+ duration: startTime,
53
+ module: obj.module,
54
+ path: obj.path,
55
+ properties: obj.properties,
56
+ sourceDomain: obj.sourceDomain,
57
+ sourceUrl: obj.sourceUrl,
58
+ title: obj.title,
59
+ traceId: "",
60
+ trackId: sdkTrackIdVal(),
61
+ url: obj.url,
62
+ visitPage: obj.visitPage,
63
+ visitTime: timeToStr(enterTimeLong),
64
+ };
65
+ if (puvData) {
66
+ insertPVUVData(puvData);
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "visual-buried-point-platform-uni",
3
- "version": "1.0.0-alpha.11",
4
- "lsi": "451804ea84c42e02c91ca4788c40d48c#1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.12",
4
+ "lsi": "4526f1e3f449c509a764a6ef609f9542#1.0.0-alpha.12",
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": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "build": "webpack --mode production && npm run lsi-md5",
9
+ "build": "rimraf dist && webpack --mode production && npm run lsi-md5",
10
10
  "lsi-md5": "node lsi-md5.js"
11
11
  },
12
12
  "type": "module",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "webpack": "^5.72.1",
25
- "webpack-cli": "4.9.2"
25
+ "webpack-cli": "4.9.2",
26
+ "rimraf": "^5.0.5"
26
27
  }
27
28
  }
@@ -0,0 +1,71 @@
1
+ import {
2
+ autoPageObj,
3
+ autoStartTrackPVUV,
4
+ autoStopTrackPVUV
5
+ } from "./autoutils.js";
6
+ import { _config } from "./index.js";
7
+
8
+ export function uniInterceptorListener() {
9
+ uni.addInterceptor("navigateTo", {
10
+ invoke(args) {
11
+ // {"url":"/pages/Home/Home/Home"}
12
+ routerMsgHandler("leave");
13
+ },
14
+ success(args) {
15
+ // {"errMsg":"switchTab:ok"}
16
+ routerMsgHandler("pv");
17
+ },
18
+ });
19
+ uni.addInterceptor("switchTab", {
20
+ invoke(args) {
21
+ routerMsgHandler("leave");
22
+ },
23
+ success(args) {
24
+ routerMsgHandler("pv");
25
+ },
26
+ });
27
+ uni.addInterceptor("navigateBack", {
28
+ invoke(args) {
29
+ routerMsgHandler("leave");
30
+ },
31
+ success(args) {
32
+ routerMsgHandler("pv");
33
+ },
34
+ });
35
+ // 切换到前台
36
+ // uni.onAppShow((res) => {
37
+ // console.log("-----onAppShow--");
38
+ // //routerMsgHandler("pv");
39
+ // });
40
+ // // 切换到后台
41
+ // uni.onAppHide(() => {
42
+ // console.log("-----onAppHide--");
43
+ // //routerMsgHandler("leave");
44
+ // });
45
+ }
46
+
47
+ // 路由消息统一处理
48
+ let pathExist = false;
49
+ function routerMsgHandler(msg) {
50
+ if (_config.isCompatible) {
51
+ } else {
52
+ if (msg === "pv") {
53
+ const pages = getCurrentPages();
54
+ const page = pages[pages.length - 1];
55
+ if (_config.signTrackArray && _config.signTrackArray.length) {
56
+ pathExist = _config.signTrackArray.find((obj) => obj === page.route);
57
+ if (pathExist) {
58
+ pathExist = true;
59
+ return;
60
+ }
61
+ }
62
+ pathExist = false;
63
+ const pageObj = autoPageObj(page.route, pages.length, pages);
64
+ autoStartTrackPVUV(pageObj);
65
+ } else if (msg === "leave") {
66
+ if (!pathExist) {
67
+ autoStopTrackPVUV();
68
+ }
69
+ }
70
+ }
71
+ }
package/tools.js CHANGED
@@ -1,3 +1,29 @@
1
+ export const AUTOTRACKTYPE = {
2
+ ENTER: "enter",
3
+ LOOP: "loop",
4
+ LEAVE: "leave",
5
+ };
6
+
7
+ export let Global = {
8
+ trackId: "",
9
+ platform: "",
10
+ uAgent: "",
11
+ upEventUrl: "",
12
+ upTrackUrl: "",
13
+ };
14
+
15
+ // 本地记录每个页面设置的属性值例如:module...
16
+ export let pagesArray = [];
17
+
18
+ export const sdkTrackIdVal = () => {
19
+ if (Global.trackId) {
20
+ return Global.trackId;
21
+ }
22
+ const tId = Date.now().toString();
23
+ Global.trackId = tId;
24
+ return tId;
25
+ };
26
+
1
27
  export function randomUUID() {
2
28
  let uuid = "xxxx-4xxx-yxxx-xxxx".replace(/[xy]/g, function (c) {
3
29
  let r = (Math.random() * 16) | 0,
@@ -25,7 +51,7 @@ export function timeToStr(timestamp) {
25
51
  }
26
52
 
27
53
  //web或者h5的appInfo
28
- export function webH5Info(result) {
54
+ export function getWebH5Info(result) {
29
55
  let ecology = "unknown";
30
56
  let ua = result.ua.toLowerCase();
31
57
  let hostname = window.location.hostname;
@@ -58,12 +84,13 @@ export function webH5Info(result) {
58
84
  packageName: hostname ? hostname : "",
59
85
  version: "",
60
86
  carrier: "h5",
61
- ecology: ecology,
87
+ //ecology: ecology,
88
+ ecology: "h5",
62
89
  };
63
90
  }
64
91
 
65
92
  //微信的appInfo
66
- export function wxInfo() {
93
+ export function getWXInfo() {
67
94
  const accInfo = uni.getAccountInfoSync();
68
95
  const bInfo = uni.getAppBaseInfo();
69
96
  return {
@@ -73,7 +100,8 @@ export function wxInfo() {
73
100
  ? accInfo.miniProgram.envVersion + accInfo.miniProgram.version
74
101
  : "",
75
102
  carrier: "mini",
76
- ecology: "wechat",
103
+ // ecology: "wechat",
104
+ ecology: "mini",
77
105
  };
78
106
  }
79
107
 
@@ -88,10 +116,10 @@ export function getAppInfo(result) {
88
116
  ecology: "",
89
117
  };
90
118
  if (result.platform === "android") {
91
- let osName = "android";
119
+ let osName = "Android";
92
120
  let pkName = plus.android.runtimeMainActivity().getPackageName();
93
121
  if (result.romName.includes("HarmonyOS")) {
94
- osName = "harmonyOS";
122
+ osName = "Harmony OS";
95
123
  }
96
124
  app.packageName = pkName ? pkName : "";
97
125
  app.ecology = osName;
@@ -101,7 +129,7 @@ export function getAppInfo(result) {
101
129
  .mainBundle()
102
130
  .bundleIdentifier();
103
131
  app.packageName = pkName ? pkName : "";
104
- app.ecology = "ios";
132
+ app.ecology = "iOS";
105
133
  } else {
106
134
  app.ecology = "unknown";
107
135
  }
@@ -134,7 +162,7 @@ export function getDeviceInfo(res, platform) {
134
162
  let device = {
135
163
  lang: res.osLanguage ? res.osLanguage : res.hostLanguage,
136
164
  brand: res.deviceBrand + " " + res.deviceModel,
137
- os: res.os,
165
+ os: res.osName,
138
166
  osVersion: res.osVersion,
139
167
  resolution: res.screenWidth + "x" + res.screenHeight,
140
168
  browser: res.browserName,
@@ -165,34 +193,44 @@ export function getDeviceInfoError() {
165
193
  }
166
194
 
167
195
  //uni 通用h5、app、wx拿到当前路由栈
168
- export function getTrackObj(busObj, platform) {
196
+ export function getTrackObj(tData) {
169
197
  const pages = getCurrentPages();
170
198
  const gcp = pages[pages.length - 1];
199
+ let pf = Global.platform;
200
+ let url = "";
201
+ let domain = "";
202
+ let srcUrl = "";
203
+ let srcDomain = "";
204
+ if (pf) {
205
+ if (pf === "web" || pf === "h5") {
206
+ url = window.location.href;
207
+ domain = window.location.hostname;
208
+ if (document.referrer) {
209
+ let parsedUrl = new URL(document.referrer);
210
+ srcUrl = parsedUrl || "";
211
+ srcDomain = parsedUrl.hostname || "";
212
+ }
213
+ } else {
214
+ url = gcp.route;
215
+ if (pages.length > 1) {
216
+ let beforePage = pages[pages.length - 2];
217
+ srcUrl = beforePage.route;
218
+ }
219
+ domain = _config.domain ? _config.domain : gcp.route;
220
+ }
221
+ }
171
222
  if (gcp) {
172
223
  return {
173
224
  path: gcp.route,
174
- domain: busObj.domain ? busObj.domain : "",
175
- url: busObj.url ? busObj.url : getUrl(platform),
176
- circulation: pages.length > 1 ? 2 : 1,
225
+ busSegment: tData.busSegment ? tData.busSegment : "",
226
+ module: tData.module ? tData.module : "",
227
+ properties: tData.extend_param ? JSON.stringify(tData.extend_param) : "",
228
+ title: tData.title ? tData.title : "",
229
+ domain: domain,
230
+ url: url,
177
231
  visitPage: pages.length,
178
- sourceDomain: busObj.sourceDomain ? busObj.sourceDomain : "",
179
- sourceUrl: busObj.sourceUrl ? busObj.sourceUrl : "",
180
- title: busObj.title ? busObj.title : "",
232
+ sourceDomain: srcDomain,
233
+ sourceUrl: srcUrl,
181
234
  };
182
235
  }
183
236
  }
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
- }
package/webpack.config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fileURLToPath } from 'url';
2
+ import { fileURLToPath } from "url";
3
3
  const __filename = fileURLToPath(import.meta.url);
4
4
  const __dirname = path.dirname(__filename);
5
5