forked from WangXueZhi/jquery.slideit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
110 lines (99 loc) · 2.67 KB
/
test.js
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
import {
apiStatisticActionLog
} from "@/api/index";
import Cookie from "js-cookie";
export default {
/**
* 自家统计方法--收集页面
* @param {String} page 页面名称
* @param {Array} args 附带数据
*/
selfPage(page = '', args = {}) {
const action = {
a: 'P',
st: this.startTime,
et: +new Date(),
page,
};
if (this.source_id) {
args.source_id = this.source_id;
}
Object.keys(args).forEach((key) => {
if (args[key] === null || args[key] === '' || args[key] === undefined) {
delete args[key];
}
});
action.args = args;
console.log('--页面统计--', action)
dataUserAnalysis([action], this);
},
/**
* 自家统计方法--收集事件
* @param {String} input 事件标签
* @param {String} output 事件输出
* @param {Object} args 附带数据
*/
selfEvent(input, output, args = {}) {
const action = {
a: 'E',
f: output,
t: input,
st: +new Date(),
};
if (output === null || output === '') {
delete action.f;
}
args.source_page = args.source_page || this.pageName;
if (this.source_id) {
args.source_id = this.source_id;
}
Object.keys(args).forEach((key) => {
if (args[key] === null || args[key] === '' || args[key] === undefined) {
delete args[key];
}
});
action.args = args;
console.log('--事件统计--', action, this)
dataUserAnalysis([action], this);
}
}
/**
* 判断是否具备上传条件
* @param {Array} data 事件列表
*/
const isCanUpAnalysis = data => {
return data.uid !== 'visitor' || data.cid !== 0;
}
/**
* 自家统计方法--上传用户行为
* @param {Array} actions 行为列表
*/
async function dataUserAnalysis(actions = [], vm) {
const { userInfo } = vm.$store.state.user;
const { cid } = userInfo;
let { uid } = userInfo;
let cookieUid = '';
let cookieCid = '';
let storageUid = '';
let storageCid = '';
try {
cookieUid = Cookie.get(CONFIG.cookie_uid_key);
cookieCid = Cookie.get(CONFIG.cookie_cid_key);
storageUid = localStorage.getItem(CONFIG.storage_uid_key);
storageCid = localStorage.getItem(CONFIG.cookie_cid_key);
console.log('Cookie.get(CONFIG.cookie_uid_key)', cookieUid);
console.log('Cookie.get(CONFIG.cookie_cid_key)', cookieCid);
} catch (error) {}
if (!uid || uid === -1) {
uid = storageUid || cookieUid;
}
const postData = {
uid: uid || 'visitor',
cid: cid || storageCid || cookieCid || $nuxt.$store.state.user.userInfo.cid || "",
actions
};
if (actions.length) {
console.log('--统计上报--', postData)
await apiStatisticActionLog(postData);
}
}