auto-point 0.0.10 → 0.0.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.
Files changed (2) hide show
  1. package/AP/auto_point.js +71 -71
  2. package/package.json +1 -1
package/AP/auto_point.js CHANGED
@@ -1,77 +1,77 @@
1
1
  class auto_point {
2
2
  // 初始化状态
3
- __INIT_STATE = true
3
+ INIT_STATE = true
4
4
  // 服务端地址
5
- __SERVER = void (0)
5
+ SERVER = void (0)
6
6
  get server() {
7
- return this.__SERVER
7
+ return this.SERVER
8
8
  }
9
9
  set server(url) {
10
- this.__SERVER = url
10
+ this.SERVER = url
11
11
  }
12
12
  // 事件列表
13
- __EVENTS = ['click']
13
+ EVENTS = ['click']
14
14
  // 发送数据间隔 单位毫秒 默认10秒
15
- __SEND_TIME = 10_000
15
+ SEND_TIME = 10_000
16
16
  // sing挂载事件元素标记
17
- __POINT_SING = "auto_point"
17
+ POINT_SING = "auto_point"
18
18
  // 埋点队列
19
- __POINT_LIST = new Array()
19
+ POINT_LIST = new Array()
20
20
  get point_list() {
21
- return this.__POINT_LIST
21
+ return this.POINT_LIST
22
22
  }
23
23
  set point_list(data){
24
- this.__POINT_LIST = data
24
+ this.POINT_LIST = data
25
25
  }
26
26
  // 埋点系统时间
27
- __POINT_SYS_INIT_TIME = void(0)
27
+ POINT_SYS_INIT_TIME = void(0)
28
28
  get point_sys_init_time(){
29
- return this.__POINT_SYS_INIT_TIME
29
+ return this.POINT_SYS_INIT_TIME
30
30
  }
31
31
  // 上次发送时间
32
- __POINT_LAST_SEND_TIME = void(0)
32
+ POINT_LAST_SEND_TIME = void(0)
33
33
  get point_last_send_time(){
34
- return this.__POINT_LAST_SEND_TIME
34
+ return this.POINT_LAST_SEND_TIME
35
35
  }
36
36
  // 中间件列表
37
- __MIDDLEWARE = new Array()
37
+ MIDDLEWARE = new Array()
38
38
 
39
- __ERROR(msg) {
39
+ ERROR(msg) {
40
40
  console.error(msg)
41
41
  }
42
- __isFunction(obj, message) {
42
+ ISFUNCTION(obj, message) {
43
43
  if (typeof obj === 'function') {
44
44
  return true
45
45
  } else {
46
- message && this.__ERROR(message)
46
+ message && this.ERROR(message)
47
47
  return false
48
48
  }
49
49
  }
50
- __NotArrowFunction(obj,message){
50
+ NOTARROWFUNCTION(obj,message){
51
51
  if (typeof obj === 'function' && obj.prototype) {
52
52
  return true
53
53
  } else {
54
- message && this.__ERROR(message)
54
+ message && this.ERROR(message)
55
55
  return false
56
56
  }
57
57
  }
58
- __isArray(array, message) {
58
+ ISARRAY(array, message) {
59
59
  if (Array.isArray(array)) {
60
60
  return true
61
61
  } else {
62
- message && this.__ERROR(message)
62
+ message && this.ERROR(message)
63
63
  return false
64
64
  }
65
65
  }
66
- __isObject(obj, message) {
66
+ ISOBJECT(obj, message) {
67
67
  if (Object.prototype.toString.call(obj) === '[object Object]') {
68
68
  return true
69
69
  } else {
70
- message && this.__ERROR(message)
70
+ message && this.ERROR(message)
71
71
  return false
72
72
  }
73
73
  }
74
- __params_hash_server(server) {
74
+ PARAMS_HASH_SERVER(server) {
75
75
  if (server) {
76
76
  return true
77
77
  } else {
@@ -81,31 +81,31 @@ class auto_point {
81
81
 
82
82
  constructor() { }
83
83
 
84
- __init(params) {
85
- if (this.__INIT_STATE && this.__isObject(params, "Init only accepts object type data") && this.__params_hash_server(params.server)) {
86
- this.__SERVER = params.server
87
- this.__SEND_TIME = params.send_time || this.__SEND_TIME
88
- this.__POINT_SING = params.point_sing || this.__POINT_SING
89
- if (params.events && this.__isArray(params.events, "events must be an Array")) {
90
- this.__EVENTS = params.events
84
+ INIT(params) {
85
+ if (this.INIT_STATE && this.ISOBJECT(params, "Init only accepts object type data") && this.PARAMS_HASH_SERVER(params.server)) {
86
+ this.SERVER = params.server
87
+ this.SEND_TIME = params.send_time || this.SEND_TIME
88
+ this.POINT_SING = params.point_sing || this.POINT_SING
89
+ if (params.events && this.ISARRAY(params.events, "events must be an Array")) {
90
+ this.EVENTS = params.events
91
91
  }
92
- this.__POINT_SYS_INIT_TIME = new Date().getTime()
93
- this.__mount_dom_event()
94
- this.__timer_send()
92
+ this.POINT_SYS_INIT_TIME = new Date().getTime()
93
+ this.MOUNT_DOM_EVENT()
94
+ this.TIMER_SEND()
95
95
  // 初始化成功埋点
96
96
  let type = "init"
97
97
  let value = "success"
98
98
  let describe = "Webpage initialization succeeded"
99
- this.__add_point(this.__create_active_point_data(type, value, describe))
100
- this.__INIT_STATE = false
99
+ this.ADD_POINT(this.CREATE_ACTIVE_POINT_DATA(type, value, describe))
100
+ this.INIT_STATE = false
101
101
  }
102
102
  }
103
103
 
104
- __create_point_data_common_params(){
104
+ CREATE_POINT_DATA_COMMON_PARAMS(){
105
105
  let point_item = new Object()
106
106
  point_item.location = JSON.parse(JSON.stringify(window.location))
107
- point_item.point_sys_init_time = this.__POINT_SYS_INIT_TIME
108
- point_item.point_last_send_time = this.__POINT_LAST_SEND_TIME
107
+ point_item.point_sys_init_time = this.POINT_SYS_INIT_TIME
108
+ point_item.point_last_send_time = this.POINT_LAST_SEND_TIME
109
109
  return point_item
110
110
  }
111
111
 
@@ -115,14 +115,14 @@ class auto_point {
115
115
  * @param {Element} element 接收一个DOM元素节点对象
116
116
  * @returns {object} 返回一个埋点数据对象point_item
117
117
  */
118
- __create_event_point_data(element) {
119
- let point_item = this.__create_point_data_common_params()
118
+ CREATE_EVENT_POINT_DATA(element) {
119
+ let point_item = this.CREATE_POINT_DATA_COMMON_PARAMS()
120
120
  point_item.point_type = "event"
121
- point_item.point_sing = this.__POINT_SING
121
+ point_item.point_sing = this.POINT_SING
122
122
  point_item.elment = element.target
123
123
  point_item.event_type = element.type
124
- point_item.point_attr = element.target.getAttribute(this.__POINT_SING)
125
- point_item.point_value = element.target.getAttribute(this.__POINT_SING)
124
+ point_item.point_attr = element.target.getAttribute(this.POINT_SING)
125
+ point_item.point_value = element.target.getAttribute(this.POINT_SING)
126
126
  return point_item
127
127
  }
128
128
 
@@ -133,8 +133,8 @@ class auto_point {
133
133
  * @param {string} activeValue 埋点动作记录值
134
134
  * @returns
135
135
  */
136
- __create_active_point_data(activeType, activeAttr, activeValue){
137
- let point_item = this.__create_point_data_common_params()
136
+ CREATE_ACTIVE_POINT_DATA(activeType, activeAttr, activeValue){
137
+ let point_item = this.CREATE_POINT_DATA_COMMON_PARAMS()
138
138
  point_item.point_type = "active"
139
139
  point_item.point_sing = activeType
140
140
  point_item.point_attr = activeAttr
@@ -143,14 +143,14 @@ class auto_point {
143
143
  }
144
144
 
145
145
  // 挂载全局监听
146
- __mount_dom_event() {
146
+ MOUNT_DOM_EVENT() {
147
147
  if (window && document && document.body) {
148
148
  let body = document.body
149
149
  // 挂载各个类型事件监听
150
- this.__EVENTS.map((item) => {
150
+ this.EVENTS.map((item) => {
151
151
  body.addEventListener(item, (e) => {
152
- if (e.target.getAttribute(this.__POINT_SING)) {
153
- this.__add_point(this.__create_event_point_data(e))
152
+ if (e.target.getAttribute(this.POINT_SING)) {
153
+ this.ADD_POINT(this.CREATE_EVENT_POINT_DATA(e))
154
154
  }
155
155
  })
156
156
  })
@@ -159,7 +159,7 @@ class auto_point {
159
159
  let type = "hashchange"
160
160
  let value = window.location.hash
161
161
  let describe = "Webpage hash value is changed to: " + window.location.hash
162
- this.__add_point(this.__create_active_point_data(type, value, describe))
162
+ this.ADD_POINT(this.CREATE_ACTIVE_POINT_DATA(type, value, describe))
163
163
  })
164
164
  // 挂载页面离开事件监听
165
165
  window.addEventListener('visibilitychange', () => {
@@ -167,8 +167,8 @@ class auto_point {
167
167
  let type = "pagehide"
168
168
  let value = "hidden"
169
169
  let describe = "Webpage hidden point"
170
- this.__add_point(this.__create_active_point_data(type, value, describe))
171
- this.__send()
170
+ this.ADD_POINT(this.CREATE_ACTIVE_POINT_DATA(type, value, describe))
171
+ this.SEND()
172
172
  }
173
173
  })
174
174
  } else {
@@ -177,34 +177,34 @@ class auto_point {
177
177
  }
178
178
 
179
179
  // 添加埋点记录
180
- __add_point(params) {
181
- if (this.__isObject(params, "Point data must be an object")) {
180
+ ADD_POINT(params) {
181
+ if (this.ISOBJECT(params, "Point data must be an object")) {
182
182
  params.time = new Date().getTime()
183
- this.__POINT_LIST.push(params)
183
+ this.POINT_LIST.push(params)
184
184
  }
185
185
  }
186
186
 
187
187
  // 发送埋点数据
188
- __send() {
189
- if (this.__POINT_LIST.length) {
190
- this.__MIDDLEWARE.map((item) => {
191
- if (this.__isFunction(item)) {
188
+ SEND() {
189
+ if (this.POINT_LIST.length) {
190
+ this.MIDDLEWARE.map((item) => {
191
+ if (this.ISFUNCTION(item)) {
192
192
  item.apply(this)
193
193
  }
194
194
  })
195
- navigator.sendBeacon(this.__SERVER, JSON.stringify(this.__POINT_LIST));
195
+ navigator.sendBeacon(this.SERVER, JSON.stringify(this.POINT_LIST));
196
196
  // 发送后清空埋点列表数据
197
- this.__POINT_LIST = new Array()
197
+ this.POINT_LIST = new Array()
198
198
  } else {
199
199
  console.log("无新埋点数据")
200
200
  }
201
201
  }
202
202
 
203
203
  // 定时发送
204
- __timer_send() {
204
+ TIMER_SEND() {
205
205
  setInterval(() => {
206
- this.__send()
207
- }, this.__SEND_TIME)
206
+ this.SEND()
207
+ }, this.SEND_TIME)
208
208
  }
209
209
 
210
210
  /**
@@ -219,13 +219,13 @@ class auto_point {
219
219
  * @param {string} [params.point_sing]
220
220
  */
221
221
  init(params) {
222
- this.__init(params)
222
+ this.INIT(params)
223
223
  return this
224
224
  }
225
225
 
226
226
  // 手动发送数据
227
227
  send() {
228
- this.__send()
228
+ this.SEND()
229
229
  }
230
230
 
231
231
  /**
@@ -234,15 +234,15 @@ class auto_point {
234
234
  * @return this
235
235
  */
236
236
  middleware(func) {
237
- if (this.__NotArrowFunction(func, "Middleware requires a non-arrow function parameter")) {
238
- this.__MIDDLEWARE.push(func)
237
+ if (this.NOTARROWFUNCTION(func, "Middleware requires a non-arrow function parameter")) {
238
+ this.MIDDLEWARE.push(func)
239
239
  }
240
240
  return this
241
241
  }
242
242
 
243
243
  // 手动添加埋点记录
244
244
  add_point(params) {
245
- this.__add_point(params)
245
+ this.ADD_POINT(params)
246
246
  }
247
247
 
248
248
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-point",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Automatic burying point",
5
5
  "main": "index.js",
6
6
  "files": [