zwUtil.js
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// 埋点对象
var zwlog;
// 页面埋点数据
var pageLogMap = {};
/*
* *******用户信息采集,同时声明 Zwlog 对象实例
* uerId 用户 ID 没登录就非必填,登录了必填
*/
export function initZwlog () {
zwlog = new ZwLog({
_user_id: localStorage.getItem('centerNo'),
// _user_nick: localStorage.getItem('_user_nick')
});
}
/*
* *******PV 日志参数- global_args
* url 页面路径 【选填】(未传参默认获取当前路由地址)
* enterPageTime 【必填】(默认在路由改变的时候自动获取时间) 进入页面的时间 new Date()
* leavePageTime 【必填】(默认在路由改变的时候自动获取时间) 离开页面的时间 new Date()
* loadTime【必填】(页面onShow中获取当前时间) 加载完的时间 new Date()
* responseTime 【必填】(页面onShow的nextTick中获取当前时间) 响应完的时间 new Date()
*/
export function zwlogPvGlobal ({
url = null,
enterPageTime = null,
leavePageTime = null,
loadTime = null,
responseTime = null
} = {}) {
console.log('调用zwlogPvGlobal')
if (!zwlog) initZwlog();
let path = url || getCurRoute();
if (!pageLogMap.hasOwnProperty(path))
pageLogMap[path] = {
enterPageTime: null,
leavePageTime: null,
loadTime: null,
responseTime: null,
};
if (enterPageTime) pageLogMap[path].enterPageTime = enterPageTime;
if (leavePageTime) pageLogMap[path].leavePageTime = leavePageTime;
if (loadTime) pageLogMap[path].loadTime = loadTime;
if (responseTime) pageLogMap[path].responseTime = responseTime;
console.log("zheliban === " + path, pageLogMap[path]);
if (
pageLogMap[path].enterPageTime &&
pageLogMap[path].leavePageTime &&
pageLogMap[path].loadTime &&
pageLogMap[path].responseTime
) {
/*
* miniAppId 应用开发管理 平台 appId
* miniAppName 应用开发管理 平台应用名称
* log_status 用户登录状态 (01:未登录/ 02:单点登录)
* Page_duration 浏览时长 用户从进入到离开当 前页面的时长
* t2 页面加载时间 页面启动到加载完成 的时间
* t0 页面响应时间 页面启动到页面响应 完成的时间
* pageId 应用页面 ID
* pageName 应用页面名称
*/
let Page_duration =
pageLogMap[path].leavePageTime.getTime() -
pageLogMap[path].enterPageTime.getTime();
let t2 =
pageLogMap[path].loadTime.getTime() -
pageLogMap[path].enterPageTime.getTime();
let t0 =
pageLogMap[path].responseTime.getTime() -
pageLogMap[path].enterPageTime.getTime();
setTimeout(() => {
let pvParams = {
miniAppId: "2002281863",
miniAppName: "绍兴研学",
log_status: "02",
// Page_duration: Page_duration / 1000 + "秒",
t2: t2 / 1000 + "秒",
t0: t0 / 1000 + "秒",
pageId: path,
pageName: getNavigationBarTitleText(),
};
zwlog.onReady(function () {
console.log('zwlog onReady')
zwlog.sendPV(pvParams);
delete pageLogMap[path];
});
}, 500);
} else {
let result = "";
for (let k in pageLogMap[path]) {
if (!pageLogMap[path][k]) result += k + ",";
}
console.log("zheliban === 浙里办页面" + path + "埋点缺少参数=>>", result);
}
}
// 获取页面的导航title
function getNavigationBarTitleText () {
// let pages = getCurrentPages();
// let page = pages[pages.length - 1];
// let title = page.$holder.navigationBarTitleText;
// console.log("zheliban === getNavigationBarTitleText title=", title);
return document.title;
}
// 点击事件的埋点
export function zwlogRecord ({ code = "" } = {}) {
if (!zwlog) initZwlog();
let path = getCurRoute();
zwlog.onReady(function () {
zwlog.record({
trackerEventCode: `${code}`,
eventType: "OTHER",
eventParams: {
pageId: path, //采用页面路径,也可以自己给每个页面设置一个pageId
pageName: getNavigationBarTitleText(),
},
});
});
}
let getCurRoute = () => {
// let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
// let curRoute = routes[routes.length - 1].route; // 获取当前页面路由,也就是最后一个打开的页面路由
// console.log("curRoute", curRoute);
return '/';
};